xaml中使用MultiBinding绑定多个属性
<Window.Resources>
<local:SpecialFeaturesConverter x:Key="SpecialFeaturesConverter" />
<local:BooltoVisibilityConvertor x:Key="InputToVisibility" />
<ControlTemplate x:Key="ValidationTemplate">
<DockPanel>
<TextBlock Foreground="Red" FontSize="20">!</TextBlock>
<AdornedElementPlaceholder />
</DockPanel>
</ControlTemplate>
</Window.Resources>
<TextBlock Text="Type Item Description" Margin="10,5,5,6" Grid.Column="1" Grid.Row="1">
<TextBlock.Visibility>
<MultiBinding Converter="{StaticResource InputToVisibility}">
<Binding ElementName="DescriptionEntryForm" Path="Text.IsEmpty" />
<Binding ElementName="DescriptionEntryForm" Path="IsFocused"/>
</MultiBinding>
</TextBlock.Visibility>
<TextBlock.Foreground>
<SolidColorBrush Opacity="0.5" Color="Black"/>
</TextBlock.Foreground>
</TextBlock>
Converter
public class BooltoVisibilityConvertor : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
bool hasText = !(bool)values[0];
bool hasFocus = (bool)values[1];
if (hasText || hasFocus)
{
return Visibility.Collapsed;
}
return Visibility.Visible;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
标签:Converter,object,用例,bool,values,MultiBinding,public
From: https://www.cnblogs.com/senya8030/p/18072464