我有這個,我知道綁定工作,因爲我用它來填充數據網格,但是當我嘗試填充行標題時,它似乎不起作用。綁定不與DataGrid上的行標題一起工作
<DataGrid Margin="150,50,150,50" x:Name="GridBinding" ItemsSource="{Binding Path=Elements[Month]}" Background="Transparent" RowBackground="Transparent" AutoGenerateColumns="False" AreRowDetailsFrozen="True" SelectionUnit="Cell" GridLinesVisibility="None" IsReadOnly="True">
<DataGrid.Columns>
<DataGridTextColumn Header="Oct." Binding="{Binding Path=Element[October].Value}" Width="*" Foreground="Black"/>
<DataGridTextColumn Header="Nov." Binding="{Binding Path=Element[November].Value}" Width="*" Foreground="Black"/>
<DataGridTextColumn Header="Dec." Binding="{Binding Path=Element[December].Value}" Width="*" Foreground="Black"/>
<DataGridTextColumn Header="Jan." Binding="{Binding Path=Element[January].Value}" Width="*" Foreground="Black"/>
<DataGridTextColumn Header="Feb." Binding="{Binding Path=Element[February].Value}" Width="*" Foreground="Black"/>
<DataGridTextColumn Header="Mar." Binding="{Binding Path=Element[March].Value}" Width="*" Foreground="Black"/>
<DataGridTextColumn Header="Apr." Binding="{Binding Path=Element[April].Value}" Width="*" Foreground="Black"/>
<DataGridTextColumn Header="May" Binding="{Binding Path=Element[May].Value}" Width="*" Foreground="Black"/>
<DataGridTextColumn Header="June" Binding="{Binding Path=Element[June].Value}" Width="*" Foreground="Black"/>
<DataGridTextColumn Header="July" Binding="{Binding Path=Element[July].Value}" Width="*" Foreground="Black"/>
<DataGridTextColumn Header="Aug." Binding="{Binding Path=Element[August].Value}" Width="*" Foreground="Black"/>
<DataGridTextColumn Header="Sep." Binding="{Binding Path=Element[September].Value}" Width="*" Foreground="Black"/>
</DataGrid.Columns>
<DataGrid.RowHeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Element[Depth].Value, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGridRowHeader}}" Foreground="#9493CF" FontSize="16" />
</DataTemplate>
</DataGrid.RowHeaderTemplate>
「DataGridRowHeader」沒有可以綁定到的「元素」屬性。你真的想指什麼? –
添加了整個代碼,並且我試圖按照我在Datagrid.columns中做的那樣做。 – Mokmeuh
再一次,您綁定到'DataGridRowHeader',它沒有可以綁定到的「Element」屬性。你說它正在填充'DataGrid'?我不知道爲什麼這是工作,因爲'DataGrid'也沒有「元素」屬性,但你可以嘗試'AncestorType = DataGrid'爲'TextBlock.Text' ... –