w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Refresh child DataContext for a tabbed window with MVVM pattern

i dont know the locator stuff, but a simple solution is the following: remove the DataContext stuff from your usercontrol

<UserControl.DataContext>
   <Binding Path="SummaryTabViewModel" Source="{StaticResource Locator}"
/>
</UserControl.DataContext>

EDIT: in addition to your comment. when you wanna change something because SelectedItem changed then why not do this in your MainViewModel?

public IPerson SelectedPerson
{
    get {...}
    set
    {
        this._selectedPerson=value;
        this.MySummary = SummaryTabViewModel(_selectedPerson);
        OnPropertyChanged("SelectedPerson");
    }
  }

 public ISummaryTabViewModel MySummary 
 {
    get {...}
    set
    {
        this._mySummary = value;
        OnPropertyChanged("MySummary");
    }
 }

xaml

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="50"/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <StackPanel Orientation="Horizontal">
        <StackPanel Orientation="Horizontal">
            <ComboBox x:Name="cbo" ItemsSource="{Binding
AvailablePersons}" IsTextSearchEnabled="True" IsEditable="False"
SelectedItem="{Binding SelectedPerson}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
        </StackPanel>
    </StackPanel>
    <TabControl Name="Test" VerticalAlignment="Top"
HorizontalAlignment="Stretch" SelectedIndex="{Binding SelectedTabIndex}"
Grid.Row="2">
        <TabItem Name="HomeTab"  Header="Summary">
            <views:SummaryTabControl DataContext="{Binding
Path=MySummary}"/>
        </TabItem>
        <TabItem Name="ContactsTab"  Header="Books">
            <views:BooksTabControl/>
        </TabItem>
    </TabControl>
</Grid>




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.