数据模板中的子控件标签

本文关键字:控件 标签 数据 | 更新日期: 2023-09-27 18:14:11

<DataTemplate x:Key="OpenDocument">
            <TextBlock>
        <Hyperlink Name="hypFileLocation" Foreground="{StaticResource XceedHyperLinkForeground}"  Cursor="Hand"  Tag="{Binding RelativeSource={RelativeSource AncestorType={x:Type xcdg:DataRow}}, Path=DataContext[OpenLocation]}" Click="Hyperlink_Click">
          <TextBlock Name="tblkDocumentName" Tag="{Binding RelativeSource={RelativeSource AncestorType={x:Type xcdg:DataRow}}, Path=DataContext[DocumentName]}"   Text="View" ToolTip="{Binding RelativeSource={RelativeSource AncestorType={x:Type xcdg:DataRow}}, Path=DataContext[DocumentName]}"/>
        </Hyperlink>
      </TextBlock>
</DataTemplate>

在xaml中,我为两个超链接&文本块内部的超链接。我想在c#中检索文本块标签值?

数据模板中的子控件标签

您可以这样做....在单击或点击事件处理程序中:

我不确定TextBlock的值,但你可以很容易地得到HyperLink的值。

.cs中的

,在事件处理程序中:

 HyperLink asd = (HyperLink)sender;
 WebBrowserTask webBrowserTask = new WebBrowserTask();            
 webBrowserTask.Uri = new Uri(asd.Tag.ToString());//here you could get the value
 webBrowserTask.Show();

同样明智地尝试Textblock,看看。

更多信息可以参考:

获取listbox windows phone 7的选定值

希望有帮助!