Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将参数传递给TreeItem中的事件_C#_Wpf - Fatal编程技术网

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,你说得对!请把答案贴出来,我会接受的。