1

UWP DataGrid:DataGrid

Q1: I want to make the columns width divided equally and make it occupy all the available width, how is that?

xaml:

<controls:DataGrid x:Name="dt_Home" AutoGenerateColumns="True"
                           CanUserResizeColumns="False"
                           AlternatingRowBackground="Gainsboro"
                           ItemsSource="{Binding UserSource, Mode=OneWay}"
                           IsReadOnly="True"/>

My DataGrid ItemSource is in my ViewModel:

public ObservableCollection<User> UserSource { get; set; } = new ObservableCollection<User>();

Q2: I want to modify the column names , for example, change the FirstName column to display FIRST NAME, how is that?

image

2
  • 1
    What did you try? Can you please provide a sample of your code as well? Commented Oct 16, 2019 at 8:24
  • Please share your XAML Commented Oct 16, 2019 at 8:54

1 Answer 1

2

Q1: I want to make the columns width divided equally and make it occupy all the available width, how is that?

You could set Columns width with proportion, if you want make all columns occupy all the available. please set each width as Width="*".

<controls:DataGrid.Columns>
    <controls:DataGridTextColumn
        Width="*"
        Binding="{Binding Id}"
        Header="ID"
        Tag="Id"
        />
    <controls:DataGridTextColumn
        Width="*"
        Binding="{Binding Title}"
        Header="Title"
        Tag="Title"
        />
    <controls:DataGridComboBoxColumn
        Width="*"
        Binding="{Binding Link}"
        Header="Link"
        ItemsSource="{x:Bind source}"
        Tag="Link"
        />
    <controls:DataGridTextColumn
        Width="*"
        Binding="{Binding Type}"
        Header="Type"
        Tag="Type"
        />
    <controls:DataGridTextColumn
        Width="*"
        Binding="{Binding Remark}"
        Header="Remark"
        Tag="Remark"
        />
    <controls:DataGridTextColumn
        Width="*"
        Binding="{Binding Time}"
        Header="Time"
        Tag="Time"
        />
</controls:DataGrid.Columns>

Q2: I want to modify the column names , for example, change the FirstName column to display FIRST NAME, how is that?

FirstName will display with DataGridTextColumn Header property, So you could edit FirstName to FIRST NAME like the follow.

<controls:DataGridTextColumn
    Width="*"
    Binding="{Binding FName}"
    Header="FIRST NAME"
    Tag="Time"
    />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.