Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Trouble finding ViewModel property from ListView

$
0
0

Hi,

I have a rather complicated data binding template and I'm not able to find away back to myViewModel to access a property and command. This is how my xaml is set up from Top to Bottom as its layout:

<HierarchicalDataTemplate x:Key="ChapterReferencesTemplate"><StackPanel><DockPanel><TextBlock Text="Chapter Reference "/><AccessText Text="{Binding Path=Chapter}" /></DockPanel><DockPanel><TextBlock Text="Total Reference Verses "/><AccessText Text="{Binding Path=Verses}" /></DockPanel><ListView Name="VerseReferencesListView" Height="200"
				ItemsSource="{Binding Path=VerseReferences}" 
				SelectedItem="{Binding Path=DataContext.CurrentVerseReference, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type src:CreateWritingsViewModel}}}"
				AlternationCount="2"
				BorderThickness="0"
				IsSynchronizedWithCurrentItem="True"><ListView.View><GridView AllowsColumnReorder="true" ColumnHeaderToolTip="xmlNamespace List" ><GridViewColumn 
						Header="Verse" 
						DisplayMemberBinding="{Binding Path=Verse}" Width="Auto"><GridViewColumn.CellTemplate><DataTemplate><TextBlock Width="Auto" TextAlignment="Left" Text="{Binding}" /></DataTemplate></GridViewColumn.CellTemplate></GridViewColumn><GridViewColumn 
						Header="Query" 
						DisplayMemberBinding="{Binding Path=Query}" Width="Auto"><GridViewColumn.CellTemplate><DataTemplate><TextBlock Width="Auto" TextAlignment="Left" Text="{Binding}" /></DataTemplate></GridViewColumn.CellTemplate></GridViewColumn><GridViewColumn Header="Actions"><GridViewColumn.CellTemplate><DataTemplate><Button 
									Command="{Binding Path=DataContext.LookupReferencesCommand, RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type src:CreateWritingsViewModel}}}" 
									CommandParameter="{Binding .}" 
									Template="{StaticResource AddButtonTemplate}"  Cursor="Hand" Width="30"/></DataTemplate></GridViewColumn.CellTemplate></GridViewColumn></GridView></ListView.View></ListView></StackPanel></HierarchicalDataTemplate>

<HierarchicalDataTemplate x:Key="WritingsReferenceTemplate"><Grid><Grid.ColumnDefinitions><ColumnDefinition MinWidth="200"/></Grid.ColumnDefinitions><GroupBox Header="{Binding Path=Hebrew}"><StackPanel Margin="5 10 5 0"><StackPanel><DockPanel><TextBlock Text="Writings of "/><AccessText Text="{Binding Path=Writings}" /></DockPanel><DockPanel><TextBlock Text="Total Reference Chapters : "/><AccessText Text="{Binding Path=Chapters}" /></DockPanel><DockPanel><TextBlock Text="Total Reference Verses : "/><AccessText Text="{Binding Path=Verses}" /></DockPanel><DockPanel ><TextBlock Text="Query for Writing : "/><AccessText Text="{Binding Path=QueryWriting}" /></DockPanel><DockPanel ><TextBlock Text="Query for Chapters : "/><AccessText Text="{Binding Path=QueryChapters}" /></DockPanel></StackPanel><DockPanel Margin="0 5 0 0"><GroupBox Header="Chapter References"><Expander><ScrollViewer VerticalScrollBarVisibility="Auto" Height="200"><HeaderedItemsControl
									ItemTemplate="{StaticResource ChapterReferencesTemplate}"
									ItemsSource="{Binding Path=ChapterReferences}"
									Margin="10,0,0,0" /></ScrollViewer></Expander></GroupBox></DockPanel></StackPanel></GroupBox></Grid></HierarchicalDataTemplate>

<GroupBox Grid.Column="1" Header="CREATE REFERENCES"><ListBox 
		Name="ReferenceListBox" 
		ItemTemplate="{StaticResource WritingsReferenceTemplate}"
		ItemsSource="{Binding Path=odsDocumentsService.WritingsReferenceItems}"
		HorizontalAlignment="Stretch"
		VerticalAlignment="Stretch"
		VirtualizingStackPanel.IsVirtualizing="False"
		VirtualizingStackPanel.VirtualizationMode="Standard"></ListBox></GroupBox>

In my HierarchicalDataTemplate x:Key="ChapterReferencesTemplate" as you can see I'm already binding toItemsSource="{Binding Path=VerseReferences}" but I also need to bind to myViewModel'sCurrentVerseReference for the SelectedItem property of theListView.

Same for my ButtonCommand to my ViewModel'sLookupReferencesCommand.  All the data is coming from bindings to aobject class that contains a ObservableCollection (ChapterReferences,VerseReferences).  The screen looks like this:

When the user selects click the plus icon is execute the XPath Query.  So far I'm having no success in getting this to work and would appreciate your help very much.

Thanks!...


Code is like a box of chocolates!...


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>