Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have recreated your problem. But I couldn't find any issue. Please look at the code below and you might get the solustion. Here is my solution.</p> <p><code>MyTab</code> view model</p> <pre><code>public class MyTab : ViewModelBase { #region Declarations private ObservableCollection&lt;string&gt; statusList; private string selectedStatus; #endregion #region Properties /// &lt;summary&gt; /// Gets or sets the header. /// &lt;/summary&gt; /// &lt;value&gt;The header.&lt;/value&gt; public string Header { get; set; } /// &lt;summary&gt; /// Gets or sets the content. /// &lt;/summary&gt; /// &lt;value&gt;The content.&lt;/value&gt; public string Content { get; set; } /// &lt;summary&gt; /// Gets or sets the status list. /// &lt;/summary&gt; /// &lt;value&gt;The status list.&lt;/value&gt; public ObservableCollection&lt;string&gt; StatusList { get { return statusList; } set { statusList = value; NotifyPropertyChanged("StatusList"); } } /// &lt;summary&gt; /// Gets or sets the selected status. /// &lt;/summary&gt; /// &lt;value&gt;The selected status.&lt;/value&gt; public string SelectedStatus { get { return selectedStatus; } set { selectedStatus = value; NotifyPropertyChanged("SelectedStatus"); } } #endregion } </code></pre> <p><code>MainViewModel</code> view model</p> <pre><code>public class MainViewModel : ViewModelBase { #region Declarations private ObservableCollection&lt;MyTab&gt; tabs; private MyTab selectedTab; #endregion #region Properties /// &lt;summary&gt; /// Gets or sets the tabs. /// &lt;/summary&gt; /// &lt;value&gt;The tabs.&lt;/value&gt; public ObservableCollection&lt;MyTab&gt; Tabs { get { return tabs; } set { tabs = value; NotifyPropertyChanged("Tabs"); } } /// &lt;summary&gt; /// Gets or sets the selected tab. /// &lt;/summary&gt; /// &lt;value&gt;The selected tab.&lt;/value&gt; public MyTab SelectedTab { get { return selectedTab; } set { selectedTab = value; NotifyPropertyChanged("SelectedTab"); } } #endregion #region Constructors /// &lt;summary&gt; /// Initializes a new instance of the &lt;see cref="MainViewModel"/&gt; class. /// &lt;/summary&gt; public MainViewModel() { this.Tabs = new ObservableCollection&lt;MyTab&gt;(); MyTab tab1 = new MyTab(); tab1.Header = "tab1"; tab1.Content = "Tab 1 content"; ObservableCollection&lt;string&gt; tab1StatusList = new ObservableCollection&lt;string&gt;(); tab1StatusList.Add("tab1 item1"); tab1StatusList.Add("tab1 item2"); tab1StatusList.Add("tab1 item3"); tab1.StatusList = tab1StatusList; tab1.SelectedStatus = tab1StatusList.First(); this.Tabs.Add(tab1); MyTab tab2 = new MyTab(); tab2.Header = "tab2"; tab2.Content = "Tab 2 content"; ObservableCollection&lt;string&gt; tab2StatusList = new ObservableCollection&lt;string&gt;(); tab2StatusList.Add("tab2 item1"); tab2StatusList.Add("tab2 item2"); tab2StatusList.Add("tab2 item3"); tab2.StatusList = tab2StatusList; tab2.SelectedStatus = tab2StatusList.First(); this.Tabs.Add(tab2); this.SelectedTab = tab1; } #endregion } </code></pre> <p>And finally this is my <code>XAML</code></p> <pre><code> &lt;Window x:Class="ComboboxSelectedItem.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:viewModel="clr-namespace:ComboboxSelectedItem.ViewModels" Title="MainWindow" Height="350" Width="525"&gt; &lt;Grid Name="mainGrid"&gt; &lt;Grid.DataContext&gt; &lt;viewModel:MainViewModel /&gt; &lt;/Grid.DataContext&gt; &lt;TabControl ItemsSource="{Binding Tabs, Mode=TwoWay}" SelectedItem="{Binding SelectedTab}"&gt; &lt;TabControl.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;TextBlock Text="{Binding Header}" Margin="0 0 20 0"/&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/TabControl.ItemTemplate&gt; &lt;!--Content section--&gt; &lt;TabControl.ContentTemplate&gt; &lt;DataTemplate&gt; &lt;Grid&gt; &lt;StackPanel Orientation="Vertical"&gt; &lt;TextBlock Text="{Binding Content}" /&gt; &lt;ComboBox ItemsSource="{Binding StatusList}" SelectedItem="{Binding SelectedStatus}" /&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/TabControl.ContentTemplate&gt; &lt;/TabControl&gt; &lt;/Grid&gt; &lt;/Window&gt; </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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      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