<DataGridTextColumn x:Name="columnCategory" Width="10*">
<DataGridTextColumn.Header>
<ComboBox HorizontalAlignment="Left"
Width="{Binding ElementName=columnCategory, Path=ActualWidth, Converter={StaticResource RightMarginSetter}, ConverterParameter=20}"/>
</DataGridTextColumn.Header>
</DataGridTextColumn>
如何在C#中编写上述XAML表达式?
答案 0 :(得分:0)
没有测试的一个例子......
ComboBox headerCombo = new ComboBox() { HorizontalAlignment = System.Windows.HorizontalAlignment.Left };
Binding myBinding = new Binding()
{
ElementName = "columnCategory",
Path = new PropertyPath("ActualWidth"),
Converter = new RightMarginSetter(),
ConverterParameter = 20
};
headerCombo.SetBinding(ComboBox.WidthProperty, myBinding);
DataGridTextColumn columnCategory = new DataGridTextColumn() { Header = headerCombo };