I have a user control that has its datacontext set to a view model named EmployeeList_VM . Then I have a ContentControl inside this user control, which has its datacontect set to the public property ( EmployeeSelection ) of the view model. ContentControl datacontext matches the binding of the selected list item within the same user control.
I want the ContentControl to bind its selected item to the EmployeeSelection datacontext ContentControl value. I want the itemssource from the combobox to bind to the public property EmployeeStatus of the parent view model EmployeeList_VM .
I can get a list of employee status that appears in the list with the list. I cannot get it to bind to the idStatus EmployeeSelection property.
Here is what I have so far (some codes have been removed for readability):
<UserControl x:Class="FTC.View.EmployeeListView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:FTC_Application" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:cmd="http://www.galasoft.ch/mvvmlight" mc:Ignorable="d" DataContext="{Binding EmployeeList_VM, Source={StaticResource Locator}}" d:DesignHeight="900" d:DesignWidth="1000"> <Expander x:Name="DetailExpander" Grid.Column="2" Header="employee detail" Style="{DynamicResource ExpanderStyle_FTC}" IsExpanded="True" Padding="8,0,0,10" > <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <StackPanel Orientation="Vertical" HorizontalAlignment="Left" > <Button Content="" Style="{DynamicResource ButtonSave}" Command="{Binding SaveCommand}" ToolTip="Save Changes" Margin="0,0,10,10"/> <Button Content="" Style="{DynamicResource ButtonUndo}" Command="{Binding UndoCommand}" ToolTip="Undo Changes" Margin="0,0,10,10"/> </StackPanel> <ScrollViewer Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <ContentControl DataContext="{Binding Path=EmployeeSelection, Mode=TwoWay}" > <Grid Grid.ColumnSpan="6" Grid.Row="1"> <Grid.ColumnDefinitions> <ColumnDefinition Width="30"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <TextBlock x:Name="SettingsHeading" Text="FTC Settings" Style="{StaticResource FTC_DetailHeading}" Grid.ColumnSpan="5"/> <TextBlock Text="Status" Style="{StaticResource FTC_DetailLabelSub}" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1"/> <ComboBox Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="2" Margin="5,5,16,5" Height="37" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},Path=DataContext.EmployeeStatus}" SelectedItem="{Binding idStatus, Mode=TwoWay}" SelectedValuePath="idStatus" DisplayMemberPath="chrCode" FontSize="18"/> </Grid> </ContentControl> </ScrollViewer> </Grid> </Expander> </UserControl>
I even tried the following change (I called ContentControl DetailControl) for the selected combobox element:
SelectedItem="{Binding ElementName=DetailControl, Path=DataContext.idStatus}"
Can someone please help me choose the right binding for the selected item. The combobox displays all the elements you need, but they do not bind to EmployeeSelection.idStatus.
Thanks in advance.