![](/img/trans.png)
[英]how to access control located in DataTemplate from a control located outside DataTemplate tag
[英]Child control Tag in DataTemplate
<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中,我为超链接和超链接内的Textblock设置了标签。 我想检索C#中的textblock标签值吗?
您可以执行以下操作。...在click或tap事件处理程序中:
我不确定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
并查看。
有关更多信息,您可以参考以下内容:
希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.