Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8773765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:23:13+00:00 2026-06-13T18:23:13+00:00

I have a relatively straightforward hierarchical data master-detail WPF window, developed using MVVM, where

  • 0

I have a relatively straightforward hierarchical data master-detail WPF window, developed using MVVM, where the Window points to a ViewModel which exposes as one of its properties the ViewModel for the detail view:

Public Class MasterViewModel
Inherits ViewModelBase ' Contains an implementation of CommandSink
Private WithEvents _ViewerSelection As DetailViewModel
Public Property ViewerSelection As DetailViewModel
    Set(value As DetailViewModel)
        _ViewerSelection = value
        RaisePropertyChanged("ViewerSelection")
    End Set
    Get
        Return _ViewerSelection
    End Get
End Property

ViewModelBase contains an implementation of Josh Smith’s VMCommanding code, which I ported to Visual Basic using the Roslyn stuff.

The XAML for the Window looks basically like this, with irrelevant details and a lot of closing brackets ommitted.

Selecting an item in the “Master” ListBox sets the DataContext of the “Detail” ListBox to a corresponding DetailViewModel. Selecting a second item in that list box changes the DataContext of the “Detail” box to the corresponding DetailViewModel of the selection. For performance reasons, once selected, the DetailViewModel is retained and switched in and out of the DataContext of the “Detail” box.

Selecting an item in the “Detail” ListBox triggers a RoutedCommand which is supposed to be caught by the ViewModel selected in the “Master” box. However, the RoutedCommands never change their focus to the correct DetailViewModel; the command is always caught by the DetailViewModel corresponding to the first “Master” ListBox selection.

What do I need to do differently?

<dx:DXWindow 
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
xmlns:local="clr-namespace:MyProject" 
Title="{Binding ProjectTitle}" 
local:CommandSinkBinding.CommandSink="{Binding}">
<dx:DXWindow.Resources>
         <local:MasterViewModel x:Key="MViewM"/>
</dx:DXWindow.Resources>
<dx:DXWindow.DataContext>
    <Binding Source="{StaticResource MViewM}" />
</dx:DXWindow.DataContext>
<Grid>
        <ListBox ItemsSource="{Binding MasterListBox}">
        <-- Selecting an item in the top list box causes a change to the DataContext
        <ListBox ItemTemplate="{StaticResource MaterialDataTemplate}" 
                Name="DetailListBox" 
                DataContext="{Binding ViewerSelection}" 
                ItemsSource="{Binding Materials}" 
                local:CommandSinkBinding.CommandSink="{Binding}" 
                SelectionMode="Multiple">
            <ListBox.CommandBindings>
                <local:CommandSinkBinding  Command="local:DetailVM.Filter"/>
            </ListBox.CommandBindings>
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <i:InvokeCommandAction Command="local:DetailVM.Filter" CommandParameter="{Binding ElementName=DetailListBox, Path=SelectedItems}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </ListBox>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:23:15+00:00Added an answer on June 13, 2026 at 6:23 pm

    I solved this by using DelegateCommands from the Prism library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a MVVM WPF application, I have a master-detail View that is used to
I have a relatively simple question. Will using PHP guarantee that a form is
I have a relatively simple class which deletes a post: function delete_post($postid, $reason){ //Stuff
I have a relatively large table (5,208,387 rows, 400mb data/670mb index), all columns i
I have a DLL which needs to access data stored in STL containers in
I have a WFC Data Service using OData v3. Following REST specification I created
Using Delphi XE to build a relatively straightforward database app using Datasnap. Since some
I think this may be relatively straight forward. I have a rewrite rule that
I have a relatively small database that I would like to generate a diagram
I have a relatively simple HTML / JavaScript form. Such as this: <form method='POST'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.