jeudi 23 novembre 2017

Black bar when increasing window size in WPF

I have a small program with two checkboxes.

The window height is 120. When one of them is checked the windows height should increase to 180. If both are checked it should increse to 220. If you uncheck them they should decrease to 180 for 1 checkbox and 120 if none are checked.

I make it smooth, that means i calculate the windowHeightOld and windowHeightNew difference, divide it through 30 and increase it in 30 small steps so it seems smooth.

The problem is that the decrease to a smaller window size looks great, the increase gives on the area that increases a black bar for a few milliseconds, then dissapears again. Sadly i could not make a screenshot because of how short its there.

I dont know where that comes from and how that could be fixed.

Here a code snipped from the increase/decrase of the window height:

if (CheckBoxSetup.IsChecked == false && CheckBoxUpdate.IsChecked == false)
{
    MainWindow1.MinHeight = 50; 

    OldWindowHeight = MainWindow1.Height;
    int NewWindowHeigth = 180;
    WindowDiff = NewWindowHeigth - OldWindowHeight;
    WindowDiff = WindowDiff / 30;
    for (int a = 0; a < 30; a++)
    {
        OldWindowHeight = OldWindowHeight + WindowDiff;
        MainWindow1.Height = OldWindowHeight;
        MainWindow1.MinHeight = OldWindowHeight; 

    }
}
if (CheckBoxSetup.IsChecked == true || CheckBoxUpdate.IsChecked == true)
{
    MainWindow1.MinHeight = 50; 

    OldWindowHeight = MainWindow1.Height;
    int NewWindowHeigth = 220;
    WindowDiff = NewWindowHeigth - OldWindowHeight;
    WindowDiff = WindowDiff / 30;
    for (int a = 0; a < 30; a++)
    {
        OldWindowHeight = OldWindowHeight + WindowDiff;
        MainWindow1.Height = OldWindowHeight;
        MainWindow1.MinHeight = OldWindowHeight; 

    }
    //MainWindow1.MinHeight = 220; 

}
if (CheckBoxSetup.IsChecked == true && CheckBoxUpdate.IsChecked == true)
{
    MainWindow1.MinHeight = 50; 

    OldWindowHeight = MainWindow1.Height;
    int NewWindowHeigth = 260;
    WindowDiff = NewWindowHeigth - OldWindowHeight;
    WindowDiff = WindowDiff / 30;
    for (int a = 0; a < 30; a++)
    {
        OldWindowHeight = OldWindowHeight + WindowDiff;
        MainWindow1.Height = OldWindowHeight;
        MainWindow1.MinHeight = OldWindowHeight; 

    }
    //MainWindow1.MinHeight = 260; 

}

if (CheckBoxSetup.IsChecked == true)
{
    LabelDestinationSetup.Visibility = Visibility.Visible;
    TextBoxDestinationpathSetup.Visibility = Visibility.Visible;
    CheckCountSetup++;
}
else
{
    LabelDestinationSetup.Visibility = Visibility.Hidden;
    TextBoxDestinationpathSetup.Visibility = Visibility.Hidden;
    CheckCountSetup--;
}
if (CheckCountSetup == 1)
{
    LabelDestinationSetup.Margin = new Thickness(24, thickTop1, 0, 0);
    TextBoxDestinationpathSetup.Margin = new Thickness(160, thickTop1, 0, 0);

    LabelDestinationUpdatepackage.Margin = new Thickness(24, thickTop2, 0, 0);
    TextBoxDestinationpathUpdatePackage.Margin = new Thickness(160, thickTop2, 0, 0);
}
if (CheckCountSetup == 0 && CheckCountUpdate == 1)
{
    LabelDestinationSetup.Margin = new Thickness(24, thickTop2, 0, 0);
    TextBoxDestinationpathSetup.Margin = new Thickness(160, thickTop2, 0, 0);

    LabelDestinationUpdatepackage.Margin = new Thickness(24, thickTop1, 0, 0);
    TextBoxDestinationpathUpdatePackage.Margin = new Thickness(160, thickTop1, 0, 0);
}
if (CheckCountSetup == 0)
{
    LabelDestinationSetup.Margin = new Thickness(24, thickTop2, 0, 0);
    TextBoxDestinationpathSetup.Margin = new Thickness(160, thickTop2, 0, 0);

    LabelDestinationUpdatepackage.Margin = new Thickness(24, thickTop1, 0, 0);
    TextBoxDestinationpathUpdatePackage.Margin = new Thickness(160, thickTop1, 0, 0);
}   
}

private void CheckBoxUpdate_Click(object sender, RoutedEventArgs e)
{
if(CheckBoxUpdate.IsChecked == true && CheckBoxFTP.IsChecked == false){
    CheckBox64Bit.IsEnabled = true;
}else if(CheckBoxUpdate.IsChecked == false){
    CheckBox64Bit.IsEnabled = false;
    CheckBox64Bit.IsChecked = false;
}
if (CheckBoxSetup.IsChecked == false && CheckBoxUpdate.IsChecked == false)
{
    MainWindow1.MinHeight = 50; 

    OldWindowHeight = MainWindow1.Height;
    int NewWindowHeigth = 180;
    WindowDiff = NewWindowHeigth - OldWindowHeight;
    WindowDiff = WindowDiff / 30;
    for (int a = 0; a < 30; a++)
    {
        OldWindowHeight = OldWindowHeight + WindowDiff;
        MainWindow1.Height = OldWindowHeight;
        MainWindow1.MinHeight = OldWindowHeight; 

    }
    //MainWindow1.MinHeight = 180; 

}
if (CheckBoxSetup.IsChecked == true || CheckBoxUpdate.IsChecked == true)
{
    MainWindow1.MinHeight = 50; 

    OldWindowHeight = MainWindow1.Height;
    int NewWindowHeigth = 220;
    WindowDiff = NewWindowHeigth - OldWindowHeight;
    WindowDiff = WindowDiff / 30;
    for (int a = 0; a < 30; a++)
    {
        OldWindowHeight = OldWindowHeight + WindowDiff;
        MainWindow1.Height = OldWindowHeight;
        MainWindow1.MinHeight = OldWindowHeight; 

    }
    //MainWindow1.MinHeight = 220; 

}
if (CheckBoxSetup.IsChecked == true && CheckBoxUpdate.IsChecked == true)
{
    MainWindow1.MinHeight = 50; 

    OldWindowHeight = MainWindow1.Height;
    int NewWindowHeigth = 260;
    WindowDiff = NewWindowHeigth - OldWindowHeight;
    WindowDiff = WindowDiff / 30;
    for (int a = 0; a < 30; a++)
    {
        OldWindowHeight = OldWindowHeight + WindowDiff;
        MainWindow1.Height = OldWindowHeight;
        MainWindow1.MinHeight = OldWindowHeight; 

    }
    //MainWindow1.MinHeight = 260; 

}
if (CheckBoxUpdate.IsChecked == true)
{
    LabelDestinationUpdatepackage.Visibility = Visibility.Visible;
    TextBoxDestinationpathUpdatePackage.Visibility = Visibility.Visible;
    CheckCountUpdate++;
}
else
{
    LabelDestinationUpdatepackage.Visibility = Visibility.Hidden;
    TextBoxDestinationpathUpdatePackage.Visibility = Visibility.Hidden;
    CheckCountUpdate--;
}
if (CheckCountUpdate == 1)
{
    LabelDestinationUpdatepackage.Margin = new Thickness(24, thickTop1, 0, 0);
    TextBoxDestinationpathUpdatePackage.Margin = new Thickness(160, thickTop1, 0, 0);

    LabelDestinationSetup.Margin = new Thickness(24, thickTop2, 0, 0);
    TextBoxDestinationpathSetup.Margin = new Thickness(160, thickTop2, 0, 0);
}
if (CheckCountSetup == 1 && CheckCountUpdate == 0)
{
    LabelDestinationUpdatepackage.Margin = new Thickness(24, thickTop2, 0, 0);
    TextBoxDestinationpathUpdatePackage.Margin = new Thickness(160, thickTop2, 0, 0);

    LabelDestinationSetup.Margin = new Thickness(24, thickTop1, 0, 0);
    TextBoxDestinationpathSetup.Margin = new Thickness(160, thickTop1, 0, 0);
}
if (CheckCountUpdate == 0)
{
    LabelDestinationUpdatepackage.Margin = new Thickness(24, thickTop2, 0, 0);
    TextBoxDestinationpathUpdatePackage.Margin = new Thickness(181, thickTop2, 0, 0);

    LabelDestinationSetup.Margin = new Thickness(24, thickTop1, 0, 0);
    TextBoxDestinationpathSetup.Margin = new Thickness(160, thickTop1, 0, 0);
}
}

Sorry for the long line of code but i thought it to be nessecary to have insight.

Basically it checks if these two are checked or not in different combinations. And increases or decreases the window height according to it. And because i also have textboxes there (thats the reason i do it. When checkboxes are checked i want to show the according textbox) which i set visible or invisible according to the checkboxes.

So basically its two methods (click Checkbox1 and click Checkbox2) and both are build the same. When one is clicked it checks for the combination, sets the window height accordingly and shows or sets the according textboxes invisible.

I hope i explained it good enough.




Aucun commentaire:

Enregistrer un commentaire