Click here to Skip to main content
13,554,127 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hello!
I have a treeview:
<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 26-Jan-13 11:51am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Why don't you use CommandParameter?

have a look on MultiBinding and Command Parameters in WPF[^]
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01-2016 | 2.8.180515.1 | Last Updated 27 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100