Je veux changer la visibilité d'une combobox dans un gridview. Lorsque la valeur est vide ou nulle, la combobox doit être cachée. Voici mon code jusqu'à présent. gvCursisten est le gridview.
Edit : Cela fonctionne dans xaml, mais pas dans cs.
<ListView Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" Grid.RowSpan="2" Name="lvTest">
<ListView.View>
<GridView x:Name="gvCursisten">
<GridViewColumn Header="Property" Width="160">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="PropertyComboBox" ItemsSource="{Binding Path=Voornaam}" Width="140" >
<ComboBox.Style>
<Style TargetType="ComboBox">
<Setter Property="Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=txtTest, Path=Text}" Value="Hoi">
<Setter Property="Visibility" Value="Hidden"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
C# code
GridViewColumn gvcCombobox2 = new GridViewColumn();
gvcCombobox2.Header = "Combobox2";
gvcCombobox2.Width = 200;
DataTemplate dteCombobox2 = new DataTemplate();
Style styleComboBox2 = new Style(typeof(ComboBox));
Setter setterStyleComboBox2 = new Setter();
setterStyleComboBox2.Property = ComboBox.VisibilityProperty;
setterStyleComboBox2.Value = Visibility.Visible;
styleComboBox2.Setters.Add(setterStyleComboBox2);
DataTrigger datatriggerStyleComboBox2 = new DataTrigger();
datatriggerStyleComboBox2.Value = "Hello";
Binding bindingDatatriggerStyleComboBox2 = new Binding("{Binding ControlType}");
datatriggerStyleComboBox2.Binding = bindingDatatriggerStyleComboBox2;
Setter setterDatatriggerStyleComboBox2 = new Setter();
setterDatatriggerStyleComboBox2.Property = ComboBox.VisibilityProperty;
setterDatatriggerStyleComboBox2.Value = Visibility.Hidden;
datatriggerStyleComboBox2.Setters.Add(setterDatatriggerStyleComboBox2);
styleComboBox2.Triggers.Add(datatriggerStyleComboBox2);
FrameworkElementFactory fefCombobox2 = new FrameworkElementFactory(typeof(ComboBox));
fefCombobox2.SetValue(ComboBox.WidthProperty, 140D);
fefCombobox2.SetValue(ComboBox.ItemsSourceProperty, dtTest.DefaultView);
fefCombobox2.SetValue(ComboBox.StyleProperty, styleComboBox2);
dteCombobox2.VisualTree = fefCombobox2;
gvcCombobox2.CellTemplate = dteCombobox2;
gvCursisten.Columns.Add(gvcCombobox2);