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

WPF TabItem content not displaying data before swiching TabItem

$
0
0

I have a problem with TabItem content not displaying data until I click on another TabItem and then I click back to the first TabItem.

I am using MVVM.

My main window is composed of a TabControl, bound to an ObservalCollection.
This TabControl ContentTemplate is composed of a user control. This user control is also composed of a TabControl.

In both the main window and the user control I set the property SelectedIndex="0".

When I click on a button, a new item is added to the ObservalCollection => 1 or more TabItems are displayed.

In the corresponding ViewModel, a thread is started, sleeping a few seconds then getting data and updating the TabItem content.

It works well except that the visible TabItem is not displaying data.
If I click on another TabItem and then back on the previously visible TabItem then the data are displayed correctly.

So my question is: what should I do to display the data in the visible TabItem as soon as the updating data thread is started, without having to switch TabItems ?

XAML code:

<Windowx:Class="Appname.Views.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:Appname.Views"xmlns:race="clr-namespace:Appname.Controls.Race"xmlns:emc="clr-namespace:Appname.Controls.ExpandingMenu"xmlns:control="clr-namespace:Appname.Controls"xmlns:wpft="http://schemas.xceed.com/wpf/xaml/toolkit"mc:Ignorable="d"Title="appname"Height="800"Width="1024"><Grid><Grid.ColumnDefinitions><ColumnDefinitionMinWidth="224"/><ColumnDefinitionWidth="4"/><ColumnDefinitionWidth="2*"/></Grid.ColumnDefinitions><!--Left Menu--><emc:ExpandingMenuControlDataContext="{Binding ExpandingMenu}"/><GridSplitterGrid.Column="1"Width="5"HorizontalAlignment="Stretch"/><!--Right part--><TabControlItemsSource="{Binding Markets}"SelectedIndex="0"Grid.Column="2"Name="TabMarkets"><TabControl.Resources><StyleTargetType="TabItem"BasedOn="{StaticResource TabStyle}"/></TabControl.Resources><TabControl.ItemTemplate><DataTemplate><TextBlockText="{Binding MarketName}"Margin="4,0"Padding="4,0"/></DataTemplate></TabControl.ItemTemplate><TabControl.ContentTemplate><DataTemplate><race:RaceControlDataContext="{Binding RaceControlViewModel }"/></DataTemplate></TabControl.ContentTemplate></TabControl></Grid>



Viewing all articles
Browse latest Browse all 18858

Trending Articles



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