Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF ComboBox selection change on TabItem selection change
    primarykey
    data
    text
    <p>I have a combobox in a tab item in MVVM. This tab can be created multiple times in my application (same view, same view model but different instance), so I can switch from one tab to another (but they are tab of the same type).</p> <p>It works perfectly with every WPF control, but with combobox I have a strange behaviour: the focus tab, when it loses focus, gets the selected item of the combox box of the tab that the application is focusing on.</p> <p>If I switch from 2 tabs that are not of the same type everything works correctly, any idea about that? Thanks.</p> <p>XAML:</p> <pre><code>&lt;CollectionViewSource x:Key="StatusView" Source="{Binding Path=StatusList}"/&gt; &lt;ComboBox Name="_spl2Status" Grid.Column="3" Grid.Row="0" ItemsSource="{Binding Source={StaticResource StatusView}}" SelectedValue="{Binding Path=CurrentSPL2.ID_SPL2_STATUS, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SelectedValuePath="FL_TYPE" DisplayMemberPath="ID_TYPE"&gt; &lt;/ComboBox&gt; </code></pre> <p>VM:</p> <pre><code>public List&lt;NullableByteEnumType&gt; StatusList { get { return (SPC_SPL2.SPL2StatusCollection.Skip(1)).ToList(); } } private SPC_SPL2 _currentSPL2 = null; public SPC_SPL2 CurrentSPL2 { get { if (_currentSPL2== null) Controller.Execute(delegate(IResult result) { Dictionary&lt;string, object&gt; parameters = new Dictionary&lt;string, object&gt;(); parameters.Add("FL_ACTIVE", true); parameters.Add("ID_SPL2", _itemcode); Model.Invalidate(typeof(SPC_SPL2), Filter.GENERIC&lt;SPC_SPL2&gt;(parameters, "ID_SPL2")); Model.Include&lt;SPC_SPL2&gt;(); if (Model.Appendload(result) == false) return false; Debug.Assert(Context.SPC_SPL2.Count == 1); _currentSPL2= Context.SPC_SPL2.FirstOrDefault(); return result.Successful; }); return _currentSPL2; } set { _currentSPL2= value; OnPropertyChanged(() =&gt; CurrentSPL2); } } </code></pre> <p>my tabs are handled in this way:</p> <pre><code>&lt;Grid&gt; &lt;Border Grid.Row="0"&gt; &lt;ContentControl Content="{Binding Path=Workspaces}" ContentTemplate="{StaticResource MasterWorkspacesTemplate}" /&gt; &lt;/Border&gt; &lt;/Grid&gt; </code></pre> <p>where</p> <pre><code> &lt;DataTemplate x:Key="MasterWorkspacesTemplate"&gt; &lt;TabControl IsSynchronizedWithCurrentItem="True" BorderThickness="0" ItemsSource="{Binding}" SelectedItem="{Binding}" ItemContainerStyleSelector="{StaticResource TabItemTemplate}" /&gt; &lt;/DataTemplate&gt; </code></pre> <p>and workspaces (my viewmodels list) (T is a class who inherit from viewModelBase)</p> <pre><code> public T CurrentWorkspace { get { return WorkspacesView.CurrentItem as T; } } private ObservableCollection&lt;T&gt; _workspaces; public ObservableCollection&lt;T&gt; Workspaces { get { if (_workspaces == null) { _workspaces = new ObservableCollection&lt;T&gt;(); _workspaces.CollectionChanged += _OnWorkspacesChanged; } return _workspaces; } } protected ICollectionView WorkspacesView { get { ICollectionView collectionView = CollectionViewSource.GetDefaultView(Workspaces); Debug.Assert(collectionView != null); return collectionView; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload