简体   繁体   English

更改 .net 核心 WPF 应用程序中的网格标签

[英]Change labels of grid in .net core WPF application

So I have a Grid on the UI that displays data(as shown in the picture and the code below), I want to change the labels of "novoIme", "staroIme", "naselenoMesto" and "opstina" into some cyrillic names.所以我在 UI 上有一个显示数据的网格(如下图和代码所示),我想将“novoIme”、“staroIme”、“naselenoMesto”和“opstina”的标签更改为一些西里尔字母名称。 I tried something like adding [Display(Name = "...")] in the Model where the properties are declared, but it doesn't work like that.我尝试在声明属性的 Model 中添加 [Display(Name = "...")] 之类的方法,但它不会那样工作。 I'm new in WPF so any ideas or suggestions will be very much welcomed.我是 WPF 的新手,因此非常欢迎任何想法或建议。 :) :)

This is the button created in XAML:这是在 XAML 中创建的按钮:

<Button Name="UlicaStaraNova"  Grid.Row="1" Content="Листа на стари и нови имиња на улици" Margin="10,0,0,0" RenderTransformOrigin="0.806,0.461" Click="UlicaStaraNova_Click"   />

This is the function that gets called once I click on the Button:这是 function,一旦我点击按钮就会被调用:

private void UlicaStaraNova_Click(object sender, RoutedEventArgs e)
        {
            DataGrid gridView = new DataGrid();
            gridView.Name = "gridViewUSN";
            gridView.ItemsSource = ListUlicaStaraNova;
            Window window = new Window();
            window.Content = gridView;
            window.Width = 670;
            window.Height = 700;
            window.ResizeMode = ResizeMode.NoResize;
            window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            window.Show();
        }

This is the window that displays on the UI once the button is clicked:这是单击按钮后在 UI 上显示的 window:

在此处输入图像描述

Or you could use Grid only.或者你可以只使用网格。 Here's the code if it helps,这是代码,如果它有帮助,

private void UlicaStaraNova_Click(object sender, RoutedEventArgs e)
        {
            Grid gridView = new Grid();
            gridView.ColumnList = new List<GridColumn>
            {
                new GridColumn("col1","col1","",""),
                new GridColumn("col2","col2","","")
            };
        }

try this:尝试这个:

gridView.Columns[0].Header="name";
gridView.Columns[1].Header="age";

or define in XAML:或在 XAML 中定义:

<DataGrid x:Name="griVeiw">
     <DataGrid.Columns>
         <DataGridTextColumn Header = "name" />
         <DataGridTextColumn Header = "age" />
    </DataGrid.Columns>
</DataGrid>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM