Skip to main content
 首页 » 编程设计

c#之WPF 绑定(bind)可见性

2024年02月05日13langtianya

我的标签应该在 RadioButton First 或 Second IsChecked=true 时可见,在 Third 时折叠或 Fourth IsChecked=false。 将按钮的名称传递给转换器并在转换器中决定它应该折叠还是可见,这只是一种方法吗?

<Grid> 
    <Grid.RowDefinitions> 
        <RowDefinition></RowDefinition> 
        <RowDefinition></RowDefinition> 
    </Grid.RowDefinitions> 
    <StackPanel Orientation="Vertical"> 
        <RadioButton Content="Visible" x:Name="First"></RadioButton> 
        <RadioButton Content="Visible" x:Name="Second"></RadioButton> 
        <RadioButton Content="Collapsed" x:Name="Third"/> 
        <RadioButton Content="Collapsed" x:Name="Fourth"></RadioButton> 
    </StackPanel> 
    <Label Content="Test" Grid.Row="1"></Label> 
</Grid> 

请您参考如下方法:

您可以实现 IMultiValueConverter 并使用它将 Visibility 绑定(bind)到多个值。 你可以找到例子 here