如何使用 IValueConverter 内部的 DependencyProperty 为网格列设置工具提示可见性
How to set ToolTip Visibility for the Grid column using DependencyProperty inside of IValueConverter
我想使用特殊逻辑在 IValueConverter
内为 ToolTip
(DependencyProperty) 设置 Visibility
。我想show/hide 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;
}
}
所以它应该有效:
<TextBlock Text="{Binding OtherData,Converter={StaticResource ToolTipMessageConverter}}" Visibility="{Binding ToolTipVisibility, Source={StaticResource ToolTipMessageConverter}}" />
我想使用特殊逻辑在 IValueConverter
内为 ToolTip
(DependencyProperty) 设置 Visibility
。我想show/hide 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;
}
}
所以它应该有效:
<TextBlock Text="{Binding OtherData,Converter={StaticResource ToolTipMessageConverter}}" Visibility="{Binding ToolTipVisibility, Source={StaticResource ToolTipMessageConverter}}" />