WPF Datatrigger Visibility + Null Value

I am starting to work in WPF. I want to set the visibility to hidden on Radiobutton when the value of the binding data is Null. I am using the WPF Toolkit. This is my code, but it does not work:

<dg:DataGrid x:Name="dtGrdData" HorizontalScrollBarVisibility="Hidden" SelectionMode="Extended" CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeRows="False" CanUserSortColumns="False" AutoGenerateColumns="False" RowHeaderWidth="0" RowHeight="50" > <DataTrigger Binding="{Binding P_DAY_PRICE}" Value="{x:Null}"> <Setter Property="RadioButton.Visibility" Value="Hidden"></Setter> </DataTrigger> <dg:DataGrid.Columns> <dg:DataGridTemplateColumn Header="1 day" Width="1.5*" > <dg:DataGridTemplateColumn.CellTemplate> <DataTemplate> <RadioButton x:Name="rdBtnDayPrice" GroupName="grpNmPrice" Content="{Binding Path=P_DAY_PRICE}" Style="{StaticResource toggleStyle}" Checked="RadioButton_Checked"></RadioButton> </DataTemplate> </dg:DataGridTemplateColumn.CellTemplate> </dg:DataGridTemplateColumn> </dg:DataGrid.Columns> </dg:DataGrid> 

Could you help me? Thanks

+4
source share
2 answers

Move the DataTrigger closer to your RadionButton :

 <RadioButton ...> <RadioButton.Style> <Style TargetType="RadioButton"> <Style.Triggers> <DataTrigger Binding="{Binding P_DAY_PRICE}" Value="{x:Null}"> <Setter Property="Visibility" Value="Hidden"></Setter> </DataTrigger> </Style.Triggers> </Style> </RadioButton.Style> </RadioButton> 
+10
source

I suggest you set the binding directly to the RadioButton and use the TargetNullValue property for the Binding object.

 <RadioButton x:Name="rdBtnDayPrice" Visibility={Binding Path=P_DAY_PRICE, TargetNullValue=Hidden, Converter=...} GroupName="grpNmPrice" Content="{Binding Path=P_DAY_PRICE}" Style="{StaticResource toggleStyle}" Checked="RadioButton_Checked" 

You will need a converter to convert the value of "P_DAY_PRICE" to the value of renaming visibility, and this should complete the task.

Riana

+3
source

Source: https://habr.com/ru/post/1345740/


All Articles