Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF TabControl Header and Content not updating?
    primarykey
    data
    text
    <p>Setup: I have a tabcontrol with 0...n tabs, and each tab is bound to a class:</p> <pre><code>class MyTabItem { string Text {get; set;} int ID {get; set;} ISet&lt;MyTabContent&gt; Contents {get; set;} } Class MyTabContent { int ID {get; set;} string Subtext {get; set;} } </code></pre> <p>Each tabitem class has many tabcontent classes in it's set. (The whole thing gets fetched via NHibernate).</p> <p>I've tried a lot of things to bind the content of MyTabItem to the header of each tabcontrol item, and the content of MyTabContent to a datagrid in the content of each tabcontrol item.</p> <p>I can display all the content in the tabs, but whenever I change properties in the bound classes, the UI does not update. I've tried to call InvalidateVisual, tried to Dispatch a Render event, tried to UpdateTarget and UpdateSource on the bindings (those last 2 threw exceptions). I've implemented INotifyPropertyChanged in my viewmodel, and even tried manually using OnPropertyChanged("MyTabItem") to no avail.</p> <p>I really don't understand why my tabcontrol contents won't update when I change properties in the bound classes. I've tried 2 different binding strategies, either works in displaying the content, but neither updates when the content changes. </p> <p>My XAML setup is:</p> <pre><code>&lt;TabControl&gt; &lt;TabControl.ItemTemplate&gt; &lt;DataTemplate DataType="models:MyTabItem"&gt; &lt;TextBlock Text="{Binding Text}" /&gt; &lt;/DataTemplate&gt; &lt;/TabControl.ItemTemplate&gt; &lt;TabControl.ContentTemplate&gt; &lt;DataTemplate DataType="models:MyTabItem"&gt; &lt;DataGrid ItemsSource="{Binding Contents}"&gt; &lt;DataGrid.Columns&gt; &lt;DataGridTextColumn Binding="{Binding Path=Subtext}" /&gt; &lt;/DataGrid.Columns&gt; &lt;/DataGrid&gt; &lt;/DataTemplate&gt; &lt;/TabControl.ContentTemplate&gt; &lt;/TabControl&gt; </code></pre> <p>With that XAML setup, I simply added Items to the tabcontrol with tabcontrol.Items.Add(new MyTabItem).</p> <p>Then I tried another XAML setup where I bound the tabcontrol.Itemsource to an ObservableCollection in the code-behind. Again, the tab content did not update if the bound properties change :(</p> <p>I also tried making a CurrentItem property in the ViewModel, and used that as a Window.Resource, and then bound the Tabcontrol contents to</p> <pre><code>{Binding Source={StaticResource CurrentItem}, Path=Text} </code></pre> <p>And whenever I changed tabs I would update the CurrentItem in the viewmodel, but with that it also didn't update changes.</p> <p>I'm pretty much out of ideas :(</p>
    singulars
    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