Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

(Solved) DataBound TabItem not updating (in Code-Behind, Cross-Thread)

$
0
0

Hi there,

I got the situation that I'm binding my TabControl to an ObservableCollection in the Code-Behind file. This OC contains instances of a class with different properties. These properties are bound to various controls inside each TabItem.

Initially this works fine, I got my TabItems for each instance and the controls display the bound values. But, when these properties are updated in events apart from the UI Thread, the controls do not update.

ObservableCollection<MyClass> Collection { get; set; }

void BindStuff()
{
    tabControl.ItemsSource = Collection;
}


void SomeOtherEvent(Args e)
{
Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => Collection.ToList().Find(f => f.Property == e.Property).Property += e.Message));
}

If I bind the Collection after the event to the TabControl, it displays the updated Collection values. Could someone give me a hint what I might be doing wrong, please?

Update: Okay it seems that there's something else wrong. I tried updating my Collection via Button, but the TabItem still doesn't show the update:

<TabControl Name="tabControl" HorizontalAlignment="Left" Height="377" Margin="98,369,0,0" VerticalAlignment="Top" Width="713"><TabControl.ItemTemplate><DataTemplate><Grid><TextBlock Text="{Binding Name}"/>    </Grid>                    </DataTemplate></TabControl.ItemTemplate><TabControl.ContentTemplate><DataTemplate><Grid Name="gridTabContent" Width="300" HorizontalAlignment="Left"><StackPanel Orientation="Vertical"><TextBlock Name="textBlockConversation" Text="{Binding Path=SomeProperty, Mode=TwoWay}" Height="200" Width="200"></TextBlock><StackPanel Orientation="Horizontal"><TextBox Width="200" Height="20" Name="textBox"></TextBox><Button Content="Send" Width="75" Height="20" Name="btnSend" Click="btnSend_Click"></Button></StackPanel></StackPanel></Grid></DataTemplate>                </TabControl.ContentTemplate></TabControl>

Update2: I solved it by adding a tabControl.Items.Refresh() to the Event.



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>