C# 将参数传递给TreeItem中的事件
有没有简单的方法可以在C# 将参数传递给TreeItem中的事件,c#,wpf,C#,Wpf,有没有简单的方法可以在TextBlock\u ismouse中直接传递Url值而不在UI上显示 <TreeView Grid.Row="1" ItemsSource="{Binding Nodes}" > <TreeView.ItemTemplate> <HierarchicalDataTemplate ItemsSource="{Binding Path=Nodes}"> <TextBlock IsMou
TextBlock\u ismouse中直接传递Url
值而不在UI上显示
<TreeView Grid.Row="1" ItemsSource="{Binding Nodes}" >
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Path=Nodes}">
<TextBlock IsMouseDirectlyOverChanged="TextBlock_IsMouseDirectlyOverChanged">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}">
<Binding Path="Name" />
<Binding Path="Url" />
</MultiBinding>
</TextBlock.Text>
<TextBlock.ToolTip>
<ToolTip Visibility="Collapsed">
<TextBlock Text="{Binding Url}"></TextBlock>
</ToolTip>
</TextBlock.ToolTip>
</TextBlock>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
数据模型:
public class Node
{
public string Name { get; set; }
public string Url { get; set; }
public ObservableCollection<Node> Nodes { get; set; }
}
公共类节点
{
公共字符串名称{get;set;}
公共字符串Url{get;set;}
公共ObservableCollection节点{get;set;}
}
您可以执行以下操作:
(Node)(((TextBlock)sender).DataContext).Url
或者按照此处的建议,您可以使用标记
属性作为参数。您可以执行以下操作:
(Node)(((TextBlock)sender).DataContext).Url
或者按照此处的建议,您可以使用标记
属性作为参数。您可以不使用(节点)((TextBlock)sender).DataContext.Url
?,或者按照此处的建议,您可以使用标记
属性作为参数parameter@Alfie,你说得对!请发布答案,我将接受。您是否可以不执行(节点)((TextBlock)发件人).DataContext.Url
?,或者按照此处的建议,您可以使用标记
属性作为parameter@Alfie,你说得对!请把答案贴出来,我会接受的。