Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF MVVM
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
0 Sergey Alexandrovich Kryukov 518
1 OriginalGriff 459
2 ChintanShukla 305
3 Richard Deeming 250
4 RyanDev 210
0 Sergey Alexandrovich Kryukov 8,901
1 OriginalGriff 7,571
2 CPallini 2,603
3 Richard MacCutchan 2,095
4 Abhinav S 1,893


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 27 Jan 2013
Copyright © CodeProject, 1999-2014
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