당신은 RadioButton
의 1,3,5 하나는이 방법을 시도 할 수 체크 할 때 Label
이 볼 수 있도록하려는 경우. 다중 바인딩 및 변환기를 정의하십시오. 변환기 :
public class LabelVisibilityConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values == null) return false;
return values.Any(v =>
{
bool? b = v as bool?;
return b.HasValue && b.Value;
});
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
이 예입니다. Convert 메서드에서 values 매개 변수의 값이 bool이고 값이 true인지 여부를 확인합니다. 여기에 마크 업 컨버터를 사용하는 방법은 다음과 같습니다
<Grid>
<Grid.Resources>
<conv:LabelVisibilityConverter x:Key="LabelConverter"/>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<StackPanel>
<RadioButton x:Name="1" Content="1"></RadioButton>
<RadioButton x:Name="2" Content="2"></RadioButton>
<RadioButton x:Name="3" Content="3"></RadioButton>
<RadioButton x:Name="4" Content="4"></RadioButton>
<RadioButton x:Name="5" Content="5"></RadioButton>
</StackPanel>
<StackPanel Grid.Row="1">
<Label Content="1">
<Label.Visibility>
<MultiBinding Converter="{StaticResource LabelConverter}">
<Binding Path="IsChecked" ElementName="1"/>
<Binding Path="IsChecked" ElementName="3"/>
<Binding Path="IsChecked" ElementName="5"/>
</MultiBinding>
</Label.Visibility>
</Label>
<Label Content="2">
<Label.Visibility>
<MultiBinding Converter="{StaticResource LabelConverter}">
<Binding Path="IsChecked" ElementName="2"/>
<Binding Path="IsChecked" ElementName="4"/>
</MultiBinding>
</Label.Visibility>
</Label>
</StackPanel>
</Grid>
로 변환 (전환 접두사)의 네임 스페이스를 매핑하는 것을 잊지 마십시오 당신은 값을 설정하는 MultiDataTrigger를 사용할 수 있습니다
xmlns:conv="clr-namespace:..."
가 응답하도록 돕는다 : 완전히 XAML에서 컨버터를 사용하지 않고? – Spontifixus
완료 코드 뒤에 값 추가가 없습니다. – GauravKP
[레이블에 대한 다중 RadioButton 가시성 바인딩]의 가능한 복제본 (http://stackoverflow.com/questions/11696924/multiple-radiobutton-visibility-binding-for-a-label) – Spontifixus