TextBlock
只有在选中CheckBox
(x:Name=DisplaySubscriber
)或Binding字符串不为空或为空时才可见。
这是我的方法:
<CheckBox Content="Display Subscriber" x:Name="DisplaySubscriber" />
<TextBlock Text="{Binding Path=SubscriberString, Mode=OneWay}" >
<TextBlock.Visibility>
<MultiBinding>
<Binding ElementName="DisplaySubscriber" Path="IsChecked" Mode="OneWay" Converter="{StaticResource BooleanToVisibleConverter}"/>
<Binding Path="SubscriberString" Mode="OneWay" Converter="{StaticResource StringIsNullEmptyConverter}"/>
</MultiBinding>
</TextBlock.Visibility>
</TextBlock>
但我收到了这个错误:
在'System.Windows.Data.MultiBinding'上提供一个值 异常。
答案 0 :(得分:3)
转换器:
openInstalledApp(<your_context>,"com.google.android.youtube");
XAML: 在资源中定义转换器:
public class TextBlockVisibilityConverter : IMultiValueConverter
{
#region IMultiValueConverter Members
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if((value[0] != null && (bool)value[0]) || (value[1]!=null && !String.IsNullOrEmpty(value[1].ToString())))
{
return Visibility.Visible;
}
return Visibility.Collapsed;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
#endregion
}
在多重绑定中使用它
<local:TextBlockVisibilityConverter x:Key="TextBlockVisibilityConverter"/>