A191919
A191919

Reputation: 3442

Pass an argument to event from TreeItem

Is there any simple way how to pass Url value in TextBlock_IsMouseDirectlyOverChanged event without showing in on 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>

DataModel:

public class Node
{
    public string Name { get; set; }

    public string Url { get; set; }

    public ObservableCollection<Node> Nodes { get; set; }
}

Upvotes: 0

Views: 92

Answers (1)

Alfie
Alfie

Reputation: 2013

You could do:

 (Node)(((TextBlock)sender).DataContext).Url

Or as suggested here Add parameter to Button click event, you could use the Tag property as a parameter.

Upvotes: 2

Related Questions