ecathell
ecathell

Reputation: 1030

Master Detail across separate views in WPF

I can get the master-detail scenario to work just fine if I keep the master and details together in the same view. However I want to be able to tailor the details presentation based on user security. Therefore I moved the detail section to a separate view using the same viewmodel as a backend. Now the details dont update properly when a new master record is selected. If the two view are using the same viewmodel, shouldnt this work just fine? Like I said when the code is together in the same view it works ok.

detail XAML:

<ListView x:Name="DoctorOfficesList"
              Grid.Column="1"
              Background="black"
              HorizontalContentAlignment="Stretch"
              IsSynchronizedWithCurrentItem="True"
              ItemsSource="{Binding Path=SelectedDoctor.DoctorOfficesCollection}"
              ItemTemplate="{StaticResource DoctorOfficesListTemplate}">
    </ListView>

Master XAML:

<ListBox x:Name="DoctorHeaderList"
             Grid.Column="0"
             MinWidth="200"
             MaxWidth="300"
             Margin="0,0,2,0"
             Background="black"
             ItemsSource="{Binding Path=DoctorsList}"
             SelectedItem="{Binding Path=SelectedDoctor}"
             IsSynchronizedWithCurrentItem="True"
             ItemTemplate="{StaticResource DoctorsListTemplate}"
             ScrollViewer.HorizontalScrollBarVisibility="Hidden">
    </ListBox>

I have tried several ways to get this to work. All scenarios work when the listboxes are in the same view. When moved separately they stop. If it matters I am using PRISMv2 as well.

I guess my specific question is how do I get this to work? Do i really need an event? I would think since they are tied to the same VM this would be a snap.

Upvotes: 0

Views: 954

Answers (1)

Robert Rossney
Robert Rossney

Reputation: 96850

Are you sure both views are using the same instance of the view model? I occasionally implement a property in my view model that exposes the result of GetHashCode() and bind a TextBlock to it in the view just to double-check that two things that are supposed to be bound to the same instance actually are.

Upvotes: 2

Related Questions