我正在尝试在ToolTip
上添加TextBlock
。经过一些研究,这是我在UWP
XAML:
<ListView x:Name="flyList" BorderThickness="0" ItemsSource="{Binding}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Border BorderThickness="0,0,0,1" BorderBrush="#FF7C7C7C">
<TextBlock Text="{Binding}" Tapped="TextBlock_Tapped">
<ToolTipService.ToolTip>
<ToolTip Name="tip1" Content="Click to copy signal to clipboard."/>
</ToolTipService.ToolTip>
</TextBlock>
</Border>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
如何设置ToolTip
的内容?或者更好,我怎么能访问它?
我想在TextBlock
的点按活动中访问它。
private void TextBlock_Tapped(object sender, TappedRoutedEventArgs e)
{
/*
var send = sender as TextBlock;
var dataPackage = new DataPackage { RequestedOperation = DataPackageOperation.Copy };
dataPackage.SetText(send.Text);
Clipboard.SetContent(dataPackage);
*/
}
答案 0 :(得分:2)
试试这个:
private void TextBlock_Tapped(object sender, TappedRoutedEventArgs e)
{
var txt = sender as TextBlock;
ToolTip tt = ToolTipService.GetToolTip(txt) as ToolTip;
tt.Content = "...";
}
请正确标记您的问题。 UWP与WPF不同。