Wpf 如何将工具提示的可见性绑定到textblock中的文本?
在上面的代码中Wpf 如何将工具提示的可见性绑定到textblock中的文本?,wpf,xaml,tooltip,Wpf,Xaml,Tooltip,在上面的代码中 <DataGrid x:Name="dgRecords1" CanUserAddRows="False" IsReadOnly="True" ColumnHeaderStyle="{DynamicResource DataGridColumnHeaderStyle1}" Style="{DynamicResource StyleDatagrid}" SelectionChanged="dgRec
<DataGrid x:Name="dgRecords1"
CanUserAddRows="False" IsReadOnly="True"
ColumnHeaderStyle="{DynamicResource DataGridColumnHeaderStyle1}"
Style="{DynamicResource StyleDatagrid}"
SelectionChanged="dgRecords1_SelectionChanged"
Height="251" Width="569" Margin="41,173,168,0">
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="ToolTip">
<Setter.Value>
<Border Width="200" Height="80"
BorderBrush="Black" BorderThickness="1"
Background="AliceBlue">
<StackPanel Orientation="Vertical">
<StackPanel Height="30" Background="Black">
<TextBlock Text="Email Sent To"
FontSize="14" FontWeight="Bold" Foreground="White"/>
</StackPanel>
<StackPanel>
<TextBlock Text="{Binding SentToList}"
TextWrapping="Wrap" FontWeight="Bold"/>
</StackPanel>
</StackPanel>
</Border>
</Setter.Value>
</Setter>
</Style>
</DataGrid.RowStyle>
我想检查这个文本块中是否有内容,如果没有,我需要使工具提示不可见。是否有一些使用触发器的方法?您可以使用工具提示控件包围边框,并使用从字符串转换为可见性的
<TextBlock TextWrapping="Wrap" FontWeight="Bold" Text="{Binding SentToList}" />
可以使用工具提示控件包围边框,并使用从字符串转换为可见性的属性将该控件的可见性绑定到相同的
SentToList
属性
<TextBlock TextWrapping="Wrap" FontWeight="Bold" Text="{Binding SentToList}" />
它工作正常,但如果有空字符串,仍会弹出一个灰色矩形小框。请参阅编辑后的答案。我已经用一个工具提示控件包围了边框(成为默认工具提示的内容),该控件取代了默认的工具提示。这个小小的灰色空工具提示让我很沮丧,谢谢。它工作正常,但如果有空字符串,仍然会弹出一个灰色矩形小框。请参见编辑后的答案。我已经用一个工具提示控件将边框(成为默认工具提示的内容)包围起来,该控件取代了默认的工具提示。这个小小的灰色空工具提示让我很沮丧,谢谢。
public class StringToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return string.IsNullOrWhiteSpace(value as string) ? Visibility.Collapsed : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}