开发者

How to set a value in a rowheadertemplate of a datagrid?

开发者 https://www.devze.com 2023-02-20 19:50 出处:网络
I\'m trying to work out a rowheadertemplate with a binding, but the binding doesn\'t work. This is what i have so far:

I'm trying to work out a rowheadertemplate with a binding, but the binding doesn't work. This is what i have so far:

       <DataGrid Name="dgFruit" ItemsSource="{Binding}" AutoGenerateColumns="false"><!--ItemTemplate="{StaticResource datagrid}"-->
            <DataGrid.RowHeaderTemplate>
                <DataTemplate>
    开发者_Python百科                <Label Content="{Binding Path=Number, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"/>
                </DataTemplate>
            </DataGrid.RowHeaderTemplate>
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Path=Name}" Header="Name"/>
                <DataGridTextColumn Binding="{Binding Path=Color}" Header="Color"/>
                <DataGridCheckBoxColumn Binding="{Binding Path=Mjummy}" Header="Mjummy"/>
            </DataGrid.Columns>
        </DataGrid>

I'm getting row headers if i set the content to a value, like "45", but when i try to bind, the rowheaders aren't shown anymore. I'm trying to bind to a property from the same class as the values in the columns.

So, how can i retrieve the Number value from my list?

Thanks in advance


seems putting it in a style works better:

        <Style TargetType="DataGridRowHeader">
            <Setter Property="Content" Value="{Binding Path=Number}" />
            <Setter Property="Padding" Value="10,0,10,0" />
        </Style>


just remove the RelativeSource thing:

<DataGrid.RowHeaderTemplate>
   <DataTemplate>
      <Label Content="{Binding Path=Number}"/>
   </DataTemplate>
</DataGrid.RowHeaderTemplate> 

The Number is a property of the dataItem, not the Grid itself.

0

精彩评论

暂无评论...
验证码 换一张
取 消