I'm new to WPF and what I want to do is below. Here is my XAML code:
...
<DataGridTextColumn Binding="{Binding ShippingNumber}" Header="出荷No." ElementStyle="{DynamicResource TextAlignCenter}" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding DivisionDisplay}" Header="区分" ElementStyle="{DynamicResource TextAlignCenter}" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding ShippingDestinationCode}" Header="出荷先コード" ElementStyle="{DynamicResource TextAlignCenter}" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding ShippingDestinationNameDisplay}" Header="出荷先名" ElementStyle="{DynamicResource TextAlignCenter}" IsReadOnly="True"/>
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="Width" Value="{Binding DataContext.CustomWidth, ElementName=Page}"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
All the logic code I have to write in ViewModel (not allow in code-behind), in the VM's constructor I set the property CustomWidth = 500
and in the RelayCommand
action of Search button I change the value to 300. It's OK to increase ctrl width to 500 at first run(load event), but then I click Search button to shrink it to 300, there is nothing happened.
Can anyone tell me why it did not take affect and how to make it works? Thanks in advance.