Have a ViewModel with two properties: Venue and States
Venue is the current view that is selected and being displayed via a form (below):
<StackPanel Orientation="Vertical" Margin="20,00,0,0" FlowDirection="LeftToRight" DataContext="{Binding Venue}">
<TextBlock Text="Venue Name" Style="{StaticResource FormHeading}" />
<TextBox x:Name="txtVenueName" Width="200" MaxLength="70" HorizontalAlignment="Left" Text="{Binding VenueName, Mode=TwoWay}" />
<TextBlock Text="Address" Style="{StaticResource FormHeading}" />
<TextBox x:Name="txtAddress" Width="300" MaxLength="100" HorizontalAlignment="Left" Text="{Binding Address, Mode=TwoWay}" />
<TextBlock Text="City" Style="{StaticResource FormHeading}" />
<TextBox x:Name="txtCity" Width="200" MaxLength="100" HorizontalAlignment="Left" Text="{Binding City, Mode=TwoWay}" />
<TextBlock Text="State" Style="{StaticResource FormHeading}" />
<ComboBox Width="70" HorizontalAlignment="Left" Name="cmbState" DisplayMemberPath="FullName"
ItemsSource="{Binding Path=States, ElementName=LayoutRoot}"/>
<TextBlock Text="Zipcode" Style="{StaticResource FormHeading}" />
<TextBox x:Name="txtZipCode" Width="50" MaxLength="5" HorizontalAlignment="Left" Text="{Binding Zipcode, Mode=TwoWay}" />
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<TextBlock Text="Active?" Style="{StaticResource FormHeading}" Margin="0,0,10,0" />
<CheckBox Name="chkActive" />
</StackPanel>
</StackPanel>
States is not a member of Venue, however, but it is a property at the same level as Venue. How can I bind to this property? Looked at RelativeSource, doesnt seem to be quite what I am looking for.
Thanks
Currently you’re setting
DataContext={Binding Venue}. One option is to remove this and then alter the other bindings to beText="{Binding Venue.VenueName, ...}"etc. You could then useItemsSource="{Binding Path=States, ..."}.Alternatively a RelativeSource binding would work. Something like:
depending on the type of the parent of the StackPanel obviously.