我想使用特殊逻辑在Visibility
内为ToolTip
(DependencyProperty)设置IValueConverter
。我想在我有特殊情况时显示/隐藏ToolTip
。
我该怎么做?
</UserControl.Resources>
<converters:ToolTipMessageConverter x:Key="ToolTipMessageConverter" />
</UserControl.Resources>
<telerik:RadGridView ItemsSource="{Binding Data}" AutoGenerateColumns="False">
<telerik:GridViewDataColumn DataMemberBinding="{Binding DataField}">
<telerik:GridViewDataColumn.ToolTipTemplate>
<TextBlock Text="{Binding OtherData,Converter={StaticResource ToolTipMessageConverter}}" Visibility=??? />
</telerik:GridViewDataColumn.ToolTipTemplate>
</telerik:GridViewDataColum>
<telerik:RadGridView>
public class ToolTipMessageConverter : FrameworkElement, IValueConverter
{
public Visibility ToolTipVisibility
{
get { return (Visibility)GetValue(ToolTipVisibilityProperty); }
set { SetValue(ToolTipVisibilityProperty, value); }
}
public static readonly DependencyProperty ToolTipVisibilityProperty =
DependencyProperty.Register("ToolTipVisibility", typeof(Visibility), typeof(ToolTipMessageConverter), new PropertyMetadata(Visibility.Visible));
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var status = (string)value;
var mess = string.Empty;
if (status == "Available")
{
this.SetValue(ToolTipVisibilityProperty, Visibility.Hidden);
}
else
{
mess = "User message... " + value;
this.SetValue(ToolTipVisibilityProperty, Visibility.Visible);
}
return mess;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
答案 0 :(得分:1)
所以它应该有效:
<TextBlock Text="{Binding OtherData,Converter={StaticResource ToolTipMessageConverter}}" Visibility="{Binding ToolTipVisibility, Source={StaticResource ToolTipMessageConverter}}" />