设置TextBlock的工具提示内容

时间:2017-02-15 19:14:21

标签: c# xaml uwp textblock

我正在尝试在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);
    */
}

1 个答案:

答案 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不同。