0

I have a WPF application with MVVM binding. I am currently redoing the navigation menu (which was in FORM before).

However, when I launch the screen, I see that it takes 7 to 8 seconds to open, which is very long compared to before. During this time, code doesn't reach ViewModel, it's still on "InitializeComponent".

The screen looks like this :

enter image description here

Each tabItem is build like this :

<TabItem
    Width="100"
    Height="40"
    Background="SteelBlue"
    Header="Usagers"
    Style="{DynamicResource TabItemStyle1}"
    ToolTip="Menu concernant les usagers"
    Visibility="{Binding TabUsagers, FallbackValue=Collapsed}">
    <Grid HorizontalAlignment="Center">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="auto" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <!--  ajouter des columnDefinition ci-dessus pour ajouter des colonnes dans l'écran  -->

        <Label
            Grid.Row="0"
            Grid.Column="0"
            Grid.ColumnSpan="6"
            HorizontalContentAlignment="Center"
            VerticalContentAlignment="Center"
            Content="Gestion des usagers"
            FontSize="24" />

        <Border
            Grid.Row="1"
            Grid.Column="0"
            Margin="5"
            VerticalAlignment="Center"
            BorderBrush="Black"
            BorderThickness="1"
            Visibility="{Binding CatUsagers, FallbackValue=Collapsed}">
            <Label
                Width="200"
                HorizontalContentAlignment="Center"
                VerticalContentAlignment="Center"
                Content="Gestion"
                FontSize="12" />
        </Border>
        <Grid Grid.Row="2" Grid.Column="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>
            <Border
                Grid.Row="0"
                Grid.Column="0"
                Margin="5"
                Padding="0,3,0,0"
                BorderBrush="Black"
                BorderThickness="1"
                Visibility="{Binding CatUsagers, FallbackValue=Collapsed}">
                <StackPanel>
                    <Button
                        Height="30"
                        Margin="3,0,3,3"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        Background="DodgerBlue"
                        Command="{Binding BtUsagersCommand}"
                        Content="Usagers"
                        Foreground="#FFF5EFEF"
                        ToolTip="Gestion des usagers"
                        Visibility="{Binding BtUsagers, FallbackValue=Collapsed}" />
                    <Button
                        Height="30"
                        Margin="3,0,3,3"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        Background="DodgerBlue"
                        Command="{Binding BtPlanningsUsagersCommand}"
                        Content="Plannings"
                        Foreground="#FFF5EFEF"
                        ToolTip="Planning usagers"
                        Visibility="{Binding BtPlanningsUsagers, FallbackValue=Collapsed}" />
                </StackPanel>
            </Border>
        </Grid>

        <Border
            Grid.Row="1"
            Grid.Column="1"
            Margin="5"
            VerticalAlignment="Center"
            BorderBrush="Black"
            BorderThickness="1"
            Visibility="{Binding CatParamUsagers, FallbackValue=Collapsed}">
            <Label
                Width="200"
                HorizontalContentAlignment="Center"
                VerticalContentAlignment="Center"
                Content="Paramètres"
                FontSize="12" />
        </Border>
        <Grid Grid.Row="2" Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>
            <Border
                Grid.Row="0"
                Grid.Column="0"
                Margin="5"
                Padding="0,3,0,0"
                BorderBrush="Black"
                BorderThickness="1"
                Visibility="{Binding CatParamUsagers, FallbackValue=Collapsed}">
                <StackPanel>
                    <Button
                        Height="30"
                        Margin="3,0,3,3"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        Background="DodgerBlue"
                        Command="{Binding BtEtablissementsUsagersCommand}"
                        Content="Etablissements"
                        Foreground="#FFF5EFEF"
                        ToolTip="Gestion des établissements des usagers"
                        Visibility="{Binding BtEtablissementsUsagers, FallbackValue=Collapsed}" />
                    <Button
                        Height="30"
                        Margin="3,0,3,3"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        Background="DodgerBlue"
                        Command="{Binding BtMutuellesUsagersCommand}"
                        Content="Grands régimes"
                        Foreground="#FFF5EFEF"
                        ToolTip="Gestion des Mutuelles décompteuses et Grands Régimes d'assurance maladie"
                        Visibility="{Binding BtMutuellesUsagers, FallbackValue=Collapsed}" />
                    <Button
                        Height="30"
                        Margin="3,0,3,3"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        Background="DodgerBlue"
                        Command="{Binding BtLieuxUsagersCommand}"
                        Content="Lieux"
                        Foreground="#FFF5EFEF"
                        ToolTip="Gestion des lieux pour les usagers"
                        Visibility="{Binding BtLieuxUsagers, FallbackValue=Collapsed}" />
                    <Button
                        Height="30"
                        Margin="3,0,3,3"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        Background="DodgerBlue"
                        Command="{Binding BtCaissesUsagersCommand}"
                        Content="Caisses"
                        Foreground="#FFF5EFEF"
                        ToolTip="Gestion des caisses primaires d'assurance maladie"
                        Visibility="{Binding BtCaissesUsagers, FallbackValue=Collapsed}" />
                    <Button
                        Height="30"
                        Margin="3,0,3,3"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        Background="DodgerBlue"
                        Command="{Binding BtCodeGestionUsagersCommand}"
                        Content="Codes gestion"
                        Foreground="#FFF5EFEF"
                        ToolTip="Gestion des codes usagers"
                        Visibility="{Binding BtCodeGestionUsagers, FallbackValue=Collapsed}" />
                </StackPanel>
            </Border>
        </Grid>
    </Grid>
</TabItem>
              

As you can see, for each button there is a binding on the visibility (each person who uses it has, according to his rights, access to some buttons and not others).

I understood that the problem comes from there, when I delete all the Visibility properties, the screen loads again instantly, in less than a second.

Is there a way to improve the way I write my XAML to avoid this long loading, or did I just put too much binding and it's unavoidable?

Edit : Visibility Method in ViewModel :

private void Visibility(List<Droit> ListeDroits)
{
   foreach (Droit droit in ListeDroits)
   {
       if(droit.Fonctions == "planning individuel")
       {
           BtEditionIndAnnuel = "Visible";
           BtEditionCollMensuel = "Visible";
           BtCollHebdoCouleur = "Visible";
           BtCollMensCouleur = "Visible";
        }
   }
}


    private string _BtEditionIndAnnuel;
    public string BtEditionIndAnnuel
    {
        get
        {
            return _BtEditionIndAnnuel;
        }
        set
        {
            if (value != _BtEditionIndAnnuel)
            {
                _BtEditionIndAnnuel = value;
                RaisePropertyChanged(nameof(BtEditionIndAnnuel));
            }
        }
    }
Sephystos
  • 175
  • 1
  • 9
  • My first guess would be that you have some UI blocking logic in Visibility property getter. Run this logic on a separate task. It'll be hard to help you without the view model class. – Maciek Świszczowski Apr 22 '21 at 08:07
  • Maciek you probably got right, this is the place where it's too long. How can i run this logic on a separate task ? – Sephystos Apr 22 '21 at 11:44

1 Answers1

0

You can try using a tabcontrol from WPF and use a style that rotates it so that the tab group appears as a vertical tab sets. You can also check this post : How to build vertical tab sets in WPF?