【问题标题】:Using MVVM in ListView on checking a checkbox show a label and on unchecking checkbox hide a label in the selected row - wpf在 ListView 中使用 MVVM 检查复选框显示标签并取消选中复选框隐藏所选行中的标签 - wpf
【发布时间】:2015-10-23 04:53:26
【问题描述】:

在我的 wpf 应用程序中,我使用的是 MVVM。在选定行的 ListView 中,我想在选中/取消选中同一选定行中的复选框时显示/隐藏标签。

【问题讨论】:

    标签: wpf listview checkbox mvvm show-hide


    【解决方案1】:

    您应该使用内置的 BooleanToVisibilityConverter,并将其绑定到 Checkbox 的 IsChecked 属性。下面是一个简单的例子。

    <Window x:Class="WpfApplication2.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/    presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <BooleanToVisibilityConverter x:Key="BoolToVis"/>
        </Window.Resources>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <CheckBox x:Name="myCheckBox" Content="CheckBox"     VerticalAlignment="Center" HorizontalAlignment="Center"><    /CheckBox>
            <TextBlock Text="Label" Grid.Row="1"      VerticalAlignment="Center" HorizontalAlignment="Center"
                Visibility="{Binding IsChecked,    ElementName=myCheckBox, Converter={StaticResource     BoolToVis}}"></TextBlock>
        </Grid>
    </Window>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多