Note that there are some explanatory texts on larger screens.

plurals
  1. POSilverlight TabControl bound to ObservableCollection<string> not updating when collection changed
    primarykey
    data
    text
    <p>Silverlight 3 app with a TabControl bound to an ObservableCollection using an IValueConverter. Initial the binding works (converter called) on app startup. Changes, Clear() or Add(), to the bound collection are not reflected in the TabControl... converter not called.</p> <p>note: the bound ListBox reflects the changes to the bound collection while the TabControl does not.</p> <p>Ideas?</p> <p>/jhd</p> <hr> <p><strong>The XAML binding...</strong></p> <pre><code>&lt;UserControl.Resources&gt; &lt;local:ViewModel x:Key="TheViewModel"/&gt; &lt;local:TabConverter x:Key="TabConverter" /&gt; &lt;/UserControl.Resources&gt; &lt;StackPanel DataContext="{StaticResource TheViewModel}"&gt; &lt;ListBox ItemsSource="{Binding Classnames}" /&gt; &lt;controls:TabControl x:Name="TheTabControl" ItemsSource="{Binding Classnames, Converter={StaticResource TabConverter}, ConverterParameter=SomeParameter}"/&gt; &lt;Button Click="Button_Click" Content="Change ObservableCollection" /&gt; &lt;/StackPanel&gt; </code></pre> <hr> <p><strong>The ViewModel...</strong></p> <pre><code>namespace DatabindingSpike { public class ViewModel { private ObservableCollection&lt;string&gt; _classnames = new ObservableCollection&lt;string&gt;(); public ViewModel() { _classnames.Add("default 1 of 2"); _classnames.Add("default 2 of 2"); } public ObservableCollection&lt;string&gt; Classnames { get { return _classnames; } set { _classnames = value; } } } } </code></pre> <hr> <p><strong>The converter (for completeness)...</strong></p> <pre><code>namespace DatabindingSpike { public class TabConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var source = value as ObservableCollection&lt;string&gt;; if (source == null) return null; var param = parameter as string; if (string.IsNullOrEmpty(param) || param != "SomeParameter") throw new NotImplementedException("Null or unknow parameter pasased to the tab converter"); var tabItems = new List&lt;TabItem&gt;(); foreach (string classname in source) { var tabItem = new TabItem { Header = classname, Content = new Button {Content = classname} }; tabItems.Add(tabItem); } return tabItems; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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