here is the first Version of my XAML Codeのプロパティを手動でバインドして、以前の質問を解決しようとしました。Width
DataGridTextColumn
<DataGrid AutoGenerateColumns="False" Background="White" ItemsSource="{Binding Items, Mode=OneWay}"
HorizontalGridLinesBrush="Silver" VerticalGridLinesBrush="Silver"
Margin="332,10,10,10" CanUserAddRows="False" CanUserDeleteRows="False"
x:Name="myDataGrid" ColumnWidth="*">
<DataGrid.Columns>
<DataGridTextColumn Width="{Binding Path=ActualWidth, Converter={StaticResource ResourceKey=WidthValueConverter}, RelativeSource={RelativeSource AncestorType=DataGrid}}" IsReadOnly="True" Header="Column1" Binding="{Binding Value1, Mode=OneWay}" />
<DataGridTextColumn Width="{Binding Path=ActualWidth, Converter={StaticResource ResourceKey=WidthValueConverter}, RelativeSource={RelativeSource AncestorType=DataGrid}}" IsReadOnly="True" Header="Column2" Binding="{Binding Value2, Mode=OneWay}"/>
<DataGridTextColumn Width="{Binding Path=ActualWidth, Converter={StaticResource ResourceKey=WidthValueConverter}, RelativeSource={RelativeSource AncestorType=DataGrid}}" IsReadOnly="True" Header="Column3" Binding="{Binding Value3, Mode=OneWay}"/>
</DataGrid.Columns>
</DataGrid>
少し調査した後、私の問題に対する答えを提供していると思われるこの投稿DataGrid
を見つけ、コードを更新しました。
<DataGrid AutoGenerateColumns="False" Background="White" ItemsSource="{Binding Items, Mode=OneWay}"
HorizontalGridLinesBrush="Silver" VerticalGridLinesBrush="Silver"
Margin="332,10,10,10" CanUserAddRows="False" CanUserDeleteRows="False"
x:Name="myDataGrid" ColumnWidth="*">
<DataGrid.Columns>
<DataGridTextColumn Width="{Binding Path=ActualWidth, Converter={StaticResource ResourceKey=WidthValueConverter}, Source={x:Reference Name=myDataGrid}}" IsReadOnly="True" Header="Column1" Binding="{Binding Value1, Mode=OneWay}" />
<DataGridTextColumn Width="{Binding Path=ActualWidth, Converter={StaticResource ResourceKey=WidthValueConverter}, Source={x:Reference Name=myDataGrid}}" IsReadOnly="True" Header="Column2" Binding="{Binding Value2, Mode=OneWay}"/>
<DataGridTextColumn Width="{Binding Path=ActualWidth, Converter={StaticResource ResourceKey=WidthValueConverter}, Source={x:Reference Name=myDataGrid}}" IsReadOnly="True" Header="Column3" Binding="{Binding Value3, Mode=OneWay}"/>
</DataGrid.Columns>
</DataGrid>
しかし、今はこの XamlParseException を取得しています
Cannot call MarkupExtension.ProvideValue because of a cyclical dependency. Properties inside a
MarkupExtension cannot reference objects that reference the result of the MarkupExtension.
The affected MarkupExtensions are:
'System.Windows.Data.Binding' Line number '37' and line position '37'.
'System.Windows.Data.Binding' Line number '38' and line position '37'.
'System.Windows.Data.Binding' Line number '39' and line position '37'.
では、どのようWidth
に aDataGridColumn
のActualWidth
プロパティをその親のプロパティにバインドできますかDataGrid