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 8441737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:38:38+00:00 2026-06-10T08:38:38+00:00

I have a view model with some fields, i.e. type ViewModel = member x.a

  • 0

I have a view model with some fields, i.e.

type ViewModel =
    member x.a = [1;2;3]
    member x.b = [4;5;6]
    member x.c = [7]

and in WPF application places some views, as:

<Control.Resources>
                    <DataTemplate x:Key="ItemTempl">
                        <TextBlock Text="{Binding}" />
                    </DataTemplate>

                    <DataTemplate x:Key="SomeTempl">
                        <ListBox ItemsSource="{Binding}"
                                 ItemTemplate="{StaticResource ItemTempl}" />
                    </DataTemplate>
                </Control.Resources>

                <StackPanel>
                    <TabControl x:Name="ListBoxViewPresenter">
                        <TabItem Header="vm.a" Content="{Binding vm.a}" 
                             ContentTemplate="{StaticResource SomeTempl}"/>
                        <TabItem Header="vm.b" Content="{Binding vm.b}" 
                             ContentTemplate="{StaticResource SomeTempl}"/>
                        <TabItem Header="vm.c" Content="{Binding vm.c}" 
                             ContentTemplate="{StaticResource SomeTempl}"/>
                    </TabControl>
                    <ListBox x:Name="ListBoxViewPresenter">
                        <ListBoxItem Content="{Binding vm.a}" 
                                     ContentTemplate="{StaticResource SomeTempl}" />
                        <ListBoxItem Content="{Binding vm.b}" 
                                     ContentTemplate="{StaticResource SomeTempl}" />
                        <ListBoxItem Content="{Binding vm.c}" 
                                     ContentTemplate="{StaticResource SomeTempl}" />
                    </ListBox>
                </StackPanel>

What should I do to achieve such behavior:
when you clicked on some element in vm.a/b/c in ListBoxViewPresenter so same element in ListBoxViewPresenter is must selected in corresponding TabItem.

UPD:
Specifically my real problem, changing from origin topic.

I have ViewModel with fields: onelines, twolines… and a field with name selected_scheme.
In xaml:

<TreeViewItem Header="{Binding Path=name}" x:Name="ProjectArea">
                    <TreeViewItem Header="Однониточные планы" Style="{StaticResource MyTreeViewItem}">
                        <ContentPresenter Content="{Binding onelines}" ContentTemplate="{StaticResource SchemeWrapperTemplate}" />
                    </TreeViewItem>
                    <TreeViewItem Header="Двухниточные планы" Style="{StaticResource MyTreeViewItem}">
                        <ContentPresenter Content="{Binding twolines}" ContentTemplate="{StaticResource SchemeWrapperTemplate}" />
                    </TreeViewItem>

And data template:

            <DataTemplate x:Key="SchemeWrapperTemplate">
            <ListBox ItemsSource="{Binding schemes}" 
                     ItemTemplate="{StaticResource SchemeTemplate}"
                     SelectedItem="{Binding selected_scheme}">
                <ListBox.Style>

In other place of the program:

 <Grid Grid.Row="1">
                    <TextBlock Text="{Binding selected_scheme.path}" />
                </Grid>

And when you click on some ListBoxes then selected item not changing if you click on a yet SelectedItems.

  • 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-10T08:38:40+00:00Added an answer on June 10, 2026 at 8:38 am

    New answer after you edited :

    It does not make much sense to bind the same object to the SelectedItem property of two different lists that contain different elements. You have to redesign your application or you may be confronted to many problems due to this strange design in the futur.

    Still, you can achieve want you want to do with a little codebehing. When the user clicks on one of your ListBox, you set the selected item of your other listbox to null. Then you will be notified when you re-click on the first listbox since the selection goes from null to something.

    xaml:

    <Window x:Class="WpfApplication13.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
            <StackPanel>
                <ListBox x:Name="ListBoxViewPresenter"
                         SelectedItem="{Binding CurrentlySelectedItem}" 
                         ItemsSource="{Binding MyItemsSource}" />
                <ListBox x:Name="ListBoxViewPresenter2"
                         SelectedItem="{Binding CurrentlySelectedItem}" 
                         ItemsSource="{Binding MyItemsSource2}" />
            </StackPanel>
        </Grid>
    </Window>
    

    codebehind:

    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Input;
    using System.ComponentModel;
    
    namespace WpfApplication13
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window, INotifyPropertyChanged
        {
            #region INotifyPropertyChanged Members
    
            public event PropertyChangedEventHandler PropertyChanged;
    
            #endregion
    
            private object _currentlySelectedItem;
    
            public object CurrentlySelectedItem
            {
                get { return _currentlySelectedItem; }
    
                set
                {
                    _currentlySelectedItem = value;
    
                    if (this.PropertyChanged != null)
                    {
                        this.PropertyChanged(this, new PropertyChangedEventArgs("CurrentlySelectedItem"));
                    }
                }
            }
    
            private List<int> _myItemsSource = new List<int> { 1, 2 };
    
            private List<int> _myItemsSource2 = new List<int> { 3, 4 };
    
            public List<int> MyItemsSource
            {
                get { return _myItemsSource; }
                set { _myItemsSource = value; }
            }
    
    
            public List<int> MyItemsSource2
            {
                get { return _myItemsSource2; }
                set { _myItemsSource2 = value; }
            }
    
            public MainWindow()
            {
                InitializeComponent();
    
                this.DataContext = this;
    
                ListBoxViewPresenter.PreviewMouseDown += ListBoxViewPresenter_PreviewMouseDown;
                ListBoxViewPresenter2.PreviewMouseDown += ListBoxViewPresenter2_PreviewMouseDown;
            }
    
            void ListBoxViewPresenter_PreviewMouseDown(object sender, MouseButtonEventArgs e)
            {
                ListBoxViewPresenter2.SelectedItem = null;
            }
    
            void ListBoxViewPresenter2_PreviewMouseDown(object sender, MouseButtonEventArgs e)
            {
                ListBoxViewPresenter.SelectedItem = null;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a property in my view model which returns a constant under some
i have the code for View and the ViewModel below and some how the
I have a view model with a property Fields which is an ObservableCollection<FieldVM> .
I have a view model that contains a Product class type and an IEnumerable<
I have following line code in my view: <td> Model.some_instance_method(args) </td> I would like
I have a view model coming from the server as json like this {
I have a view model that looks like this public class ViewModelRound2 { public
I have a view model with an Email address property and a Confirm Email
I have this view @model IEnumerable<ViewModelRound2> ... <snip> ... @{ using (Html.BeginForm(new { round1Ring3Bids
I have a view model with a couple of properties that are not displaying

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.