Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello!
I have a treeview:
XML
<TreeView  
    BorderBrush="Black" 
    BorderThickness="2" 
    Cursor="Hand" 
    ItemsSource="{Binding Data, UpdateSourceTrigger=PropertyChanged}" >
    <TreeView.ItemContainerStyle>
	<Style TargetType="{x:Type TreeViewItem}">
		<Setter 
                    Property="IsSelected" 
                    Value="{Binding SelectedPath, Mode=TwoWay}" />
		</Style>
    </TreeView.ItemContainerStyle>
    <TreeView.ItemTemplate>
        <HierarchicalDataTemplate 
            ItemsSource="{
                            Binding Persons, 
                            UpdateSourceTrigger=PropertyChanged}" 
            DataType="{x:Type local:Data}" >
            <Grid>
		<StackPanel Orientation="Horizontal">
    		<TextBlock x:Name="dane" Text="{Binding ID}" Margin="0,0,5,0" />
                <Button 
                    Style="{StaticResource ButtonLikeTextBlock}" 
                    Content="{Binding DataOrName}" 
                    Command="
                            {Binding 
                                    Path=DataContext.DisplayInfoCommand, 
                                    RelativeSource = {RelativeSource FindAncestor, AncestorType={x:Type Window}}}" />
								
		</StackPanel>
            </Grid>
        </HierarchicalDataTemplate>
    </TreeView.ItemTemplate>
</TreeView>


How can i get the ID property which is in Persons list ? How can i bind it straight to viewmodel class? Can u show sample code?

Greetings, Boryborawski.
Posted

1 solution

Why don't you use CommandParameter?

have a look on MultiBinding and Command Parameters in WPF[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900