我正在创建一个CheckBox
列表和一个ComboBox
,其中包含WPF MVVM应用程序中选中的复选框的列表。我不知道如何绑定复选框中选中的组合框的文本。
以下是我尝试过的方法:
<ComboBox ItemsSource="{Binding Systems}" Grid.Row="4" Grid.Column="1"
IsEditable="True" IsReadOnly="True" Text="{}">
<ComboBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding TemplateName}" IsChecked="{Binding
IsSystemChecked, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
发布于 2019-05-23 19:03:31
这应该能起到作用:
<StackPanel>
<ListView ItemsSource="{Binding Systems}" >
<ListView.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding TemplateName}" IsChecked="{Binding
IsSystemChecked, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ComboBox ItemsSource="{Binding Systems}" DisplayMemberPath="TemplateName" >
<ComboBox.Style>
<Style TargetType="ComboBox">
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="ComboBoxItem" BasedOn="{StaticResource {x:Type ComboBoxItem}}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsSystemChecked}" Value="False">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</Setter.Value>
</Setter>
</Style>
</ComboBox.Style>
</ComboBox>
</StackPanel>
下面是:
绑定到包含Systems
中所有项的IsSystemChecked
property
ComboBox
的Systems
中包含每个项目的复选框的Visibility
,但是,如果IsSystemChecked
属性为false,则Visibility
将设置为Collapsed
,因此不会在中显示
如果你有任何问题,请告诉我!希望这能有所帮助。
https://stackoverflow.com/questions/56271880
复制相似问题