Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UI tab control visibility changes between debug and deployed version

I have a WPF Mvvm-Light application that uses tab controls to display different views to the user.

PROBLEM:

THe problem I have is that when the program first loads the tab control displays empty. But when debugging locally this problem never occurs. This application has been in development for over a year without this issue and all of a sudden it started happening. see below image enter image description here

HACK FIX:

If the user resizes their window, the content in the tab control refreshes and appears and the problem never reoccurs while they have the application open. But this issue occurs 100% of the time on first program load and first tab load (which happens at the same time)

DETAILS:

here is how I define my views that get inserted into the tab control

 <DataTemplate DataType="{x:Type FtcViewModel:DashboardNavViewModel}">
   <FtcView:DashboardNav  />
 </DataTemplate>

and here is my tab control:

<TabControl  Grid.Column="1" Grid.Row="3" 
                     SelectedItem="{Binding CurrentViewModel}" 
                     ItemsSource="{Binding OpenViewModelCollection}" 
                     Style="{StaticResource TabControlStyle}" 
                     ItemContainerStyle="{StaticResource TabItemStyle}" >
        </TabControl>

then in my view model for the main window i assign a collection to the tab control and by default set the dashbaord as the first tab to open like this (tried to only include relevant code, obiously there is more in the viewModel file):

Public Property OpenViewModelCollection As ObservableCollection(Of ViewModelHelper)
    Get
        Return Me._OpenViewModelCollection
    End Get
    Set(value As ObservableCollection(Of ViewModelHelper))
        If _OpenViewModelCollection Is value Then
            Return
        End If
        _OpenViewModelCollection = value
        RaisePropertyChanged(OpenViewModelCollectionPropertyName)
    End Set
End Property

Public Property CurrentViewModel As ViewModelHelper
            Get
                Return Me._CurrentViewModel
            End Get
            Set(value As ViewModelHelper)
                If _CurrentViewModel Is value Then
                    Return
                End If
                ''if change of viewmodel is not from OpenTabViewModelCommandExecute method
                If FlagOpening = False AndAlso value IsNot Nothing Then

                    If _CurrentViewModel IsNot Nothing Then
                        _CurrentViewModel.HandleNavigation(True)
                    End If

                    ''Mark NavService target VM
                    _NavService.TargetViewModelKey = value.vmKey

                    ''evaluate if naviagtion has been canceled
                    If _NavService.bCanNavigate = False Then
                        _NavService.bCanNavigate = True
                        Exit Property
                    End If
                End If
                ''if navigation not canceled, finish assigning new view model
                _CurrentViewModel = value
                RaisePropertyChanged(CurrentViewModelPropertyName)
                If _CurrentViewModel IsNot Nothing Then
                    _CurrentViewModel.RefreshModel()
                End If
            End Set
        End Property
...

'' THIS CODE IS FROM THE CONSTRUCTOR OF THE VIEW MODEL CLASS
OpenViewModelCollection.Add(_Locator.DashboardHome_VM)
CurrentViewModel = OpenViewModelCollection(0)

QUESTION

can someone help me figure out why this is happening or suggest a way to refresh the UI after the first application load.

thanks in advance

UPDATE 1 - Oct 4, 2017

I have been able to reproduce this problem on my development machine. When the UI is blank you can see that the XAML diagnostics tools don't show up. THe image below shows the same app being debugged, but the one without the XAML tools box is the one with the missing ui elements.

enter image description here

The following content is not being rendered inside my custom tab control style:

<ScrollViewer VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Auto" >
    <ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</ScrollViewer>

EDIT 2 Oct 11 2017

I have set breakpoints in both the xaml and code in the ViewModel. I can confirm that the ViewModel data is correctly initialized and assigned to the observable objects. I also inserted "test" textblocks in my tabItemTemplate to confirm which part is not showing. Right now I have a terrible hack of resizing the window from code on application startup, while that works, I still would like to figure out what is going on.

like image 650
J King Avatar asked Sep 29 '17 20:09

J King


1 Answers

This is quite hacky but you could try something like this:

Public Sub YourFormName.OnLoad ()
    Dim CorrectFormSize As Intager = YourFormName.Size
    YourFormName.Size = New Size(300, 300)
    System.Threading.Thread.Sleep(1000)
    YourFormName.Size = New Size(CorrectFormSize)
End Sub

Bear in mind that this will just automate the resize process that you described.

If you want to save a few lines because you application is going to be full screen once loaded then you can skip a few lines and do this instead:

Public Sub YourFormName.OnLoad()
    YourFormName.Size = New Size(300, 300)
    System.Threading.Thread.Sleep(1000)
    YourFormName.WindowState = System.Windows.Forms.FormWindowState.Maximized
End Sub
like image 67
T54 Avatar answered Oct 31 '22 07:10

T54