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

  • SEARCH
  • Home
  • 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 8100477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:44:40+00:00 2026-06-05T22:44:40+00:00

I am working on a wpf application using PRISM. This is my first ever

  • 0

I am working on a wpf application using PRISM. This is my first ever WPF application and I have found myself in a situation where I can’t go forward.

My scenario is this, I have a List of groups which I am binding with a ListBox, you can call it parent ListBox, each group object has a list of users associated to it and I am binding that list with another ListBox which is nested in the parent ListBox. Both bindings are working fine as you can see here:

enter image description here

I am facing two problems.

1. I can select both groups and individual users withing group separately but they are not synch, means If i select a user then the group which contains this user is not getting selected. I tried IsSynchronizedWithCurrentItem=”True” but that doesn’t seems to be working.

I would greatly appreciate if someone can point me out in a right direction how to achieve this or if there is any other way beside using ListBox within a ListBox.

2. I have a context menu associated with parent ListBox and I am able to successfully bind the commands with menus, but I am having troubles binding commands with nested ListBox Context Menu, here is my code

<ListBox x:Name="lstOfGroups" 
             ItemsSource="{Binding CurrentContest.Groups}"
             SelectedItem="{Binding SelectedGroup}"
             ItemTemplate="{StaticResource GroupTemplate}"
             Style="{StaticResource ListBoxStyle1}"
             ItemContainerStyle="{StaticResource ListBoxItemStyle1}"
             Background="Transparent" SelectionMode="Single"
             IsSynchronizedWithCurrentItem="True"
             Height="400">
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel Orientation="Horizontal" Margin="5" Width="1200"/>
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>

                <ListBox.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="Add Contestant" Command="{Binding AddGroupCommand}"/>
                        <MenuItem Header="Edit Contestant" Command="{Binding EditGroupCommand}"/>
                        <MenuItem Header="Delete Contestant" Command="{Binding DeleteGroupCommand}"/>
                    </ContextMenu>
                </ListBox.ContextMenu>
            </ListBox>

<DataTemplate x:Key="GroupTemplate" >
        <Border x:Name="spPubItemBorder" Margin="3" BorderBrush="Black" BorderThickness="1" CornerRadius="10" Background="Honeydew">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <StackPanel Orientation="Horizontal">
                    <TextBlock Name="tbGroupName" Grid.Column="0" Style="{StaticResource ItemTextBox}">
                    <TextBlock.Text>
                        <MultiBinding StringFormat="{}Group Name: {0}">
                            <Binding Path="Name" />
                        </MultiBinding>
                    </TextBlock.Text>
                    </TextBlock>
                    <TextBlock Name="tbGroupAmount" Grid.Column="1" Style="{StaticResource ItemTextBox}">
                    <TextBlock.Text>
                        <MultiBinding StringFormat="{}Group Amount: {0}">
                            <Binding Path="Amount" />
                        </MultiBinding>
                    </TextBlock.Text>
                    </TextBlock>
                </StackPanel>
                <!--<ItemsControl ItemsSource="{Binding ContestantList}"
                              AlternationCount="2" ItemTemplate="{StaticResource ContestantTemplate}">

                </ItemsControl>-->
                <ListBox x:Name="lstOfContestant" Grid.Row="1"
                     ItemsSource="{Binding ContestantList}"
                     SelectedItem="{Binding SelectedContestant, ElementName=lstOfGroups}"
                     ItemTemplate="{StaticResource ContestantTemplate}"
                     Style="{StaticResource ListBoxStyleForContestant}"
                     ItemContainerStyle="{StaticResource ListBoxItemStyleForContestant}"
                     Background="Transparent" SelectionMode="Single"
                     Height="Auto">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel Orientation="Horizontal" Margin="5" Width="375"/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>

                    <ListBox.ContextMenu>
                        <ContextMenu>
                            <MenuItem Header="Add Contestant" Command="{Binding Path=DataContext.AddContestantCommand,ElementName=contestantManager}"/>
                            <MenuItem Header="Edit Contestant" Command="{Binding Path=DataContext.EditContestantCommand,ElementName=contestantManager}"/>
                            <MenuItem Header="Delete Contestant" Command="{Binding Path=DataContext.DeleteContestantCommand,ElementName=contestantManager}"/>
                        </ContextMenu>
                    </ListBox.ContextMenu>
                </ListBox>

            </Grid>
        </Border>
    </DataTemplate>

I was wondering if someone can point me in a right direction here as well.

Thanks in advance.

  • 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-05T22:44:41+00:00Added an answer on June 5, 2026 at 10:44 pm

    For #1, set the IsSelected property of the group ListBox to true if IsKeyboardFocusWithin

    <Style x:Key="GroupListBoxItemStyle" TargetType="ListBoxItem">
      <Style.Triggers>
        <Trigger Property="IsKeyboardFocusWithin" Value="True">
          <Setter Property="IsSelected" Value="True" />
        </Trigger>
      </Style.Triggers>
    </Style>
    

    This will set the group’s ListBoxItem as Selected when the keyboard focus is anywhere within the ListBoxItem

    As for #2, it sounds like you’re getting the wrong item, probably because you’re using ElementName in your binding, however the name is set on multiple items. Try using a RelativeSource binding to find the ContextMenu itself, then bind to the PlacementTarget.DataContext

    <MenuItem Header="Add Contestant"
              Command="{Binding PlacementTarget.DataContext.AddContestantCommand, 
                  RelativeSource={RelativeSource FindAncestor, 
                  AncestorType={x:Type ContextMenu}}}" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have the beginnings of a modular wpf application built using prism. We want
I have a WPF application using MVVM that utilises TreeViewItemViewModels to simplify working with
I'm currently using PrintVisual() in a wpf application to do printing. This is working
I'm working on a WPF application, and I'm structuring it using the MVVM pattern.
I'm working on writing a small application using the WPF MediaKit , and I
I'm building a WPF application and working with the MVVM pattern. I have 4
I am working on a WPF application with MVVM, but am not using any
I am working on a WPF/Prism 4/AvalonDoc application. One of my views is very
I'm working on an WPF application using the mvvm-light framework. I'm new to both
I am working on a WPF application and using a scrollViewer to view the

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.