Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在WPF中增加窗口大小时出现黑条_C#_Wpf_Checkbox_Window - Fatal编程技术网

C# 在WPF中增加窗口大小时出现黑条

C# 在WPF中增加窗口大小时出现黑条,c#,wpf,checkbox,window,C#,Wpf,Checkbox,Window,我有一个带有两个复选框的小程序 窗户的高度是120。检查其中一个后,窗高度应增加到180。如果两者都选中,则应增加到220。如果您取消选中它们,则对于1复选框,它们应减少到180;如果未选中任何复选框,它们应减少到120 我使它平滑,这意味着我计算windowHeightOld和windowHeightNew的差值,将其除以30,然后分30小步增加,使其看起来平滑 问题是,减小到较小的窗口大小看起来很棒,增加的区域会增加一个黑色条,持续几毫秒,然后再次消失。遗憾的是,我无法截图,因为它有多短 我

我有一个带有两个复选框的小程序

窗户的高度是120。检查其中一个后,窗高度应增加到180。如果两者都选中,则应增加到220。如果您取消选中它们,则对于1复选框,它们应减少到180;如果未选中任何复选框,它们应减少到120

我使它平滑,这意味着我计算windowHeightOld和windowHeightNew的差值,将其除以30,然后分30小步增加,使其看起来平滑

问题是,减小到较小的窗口大小看起来很棒,增加的区域会增加一个黑色条,持续几毫秒,然后再次消失。遗憾的是,我无法截图,因为它有多短

我不知道这是从哪里来的,也不知道如何解决

此处,从窗口高度的增加/减少中截取了一个代码:

private void CheckBoxSetup_Click(object sender, RoutedEventArgs e)
    {

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);
}
}
private void CheckBoxSetup\u单击(对象发送方,路由目标)
{
if(CheckBoxSetup.IsChecked==false&&CheckBoxUpdate.IsChecked==false)
{
MainWindow1.MinHeight=50;
OldWindowHeight=MainWindow1.高度;
int NewWindowHeigth=180;
WindowDiff=新窗高-旧窗高;
WindowDiff=WindowDiff/30;
对于(int a=0;a<30;a++)
{
OldWindowHeight=OldWindowHeight+WindowDiff;
MainWindow1.高度=旧窗口高度;
MainWindow1.MinHeight=旧窗口高度;
}
}
if(CheckBoxSetup.IsChecked==true | | CheckBoxUpdate.IsChecked==true)
{
MainWindow1.MinHeight=50;
OldWindowHeight=MainWindow1.高度;
int NewWindowHeigth=220;
WindowDiff=新窗高-旧窗高;
WindowDiff=WindowDiff/30;
对于(int a=0;a<30;a++)
{
OldWindowHeight=OldWindowHeight+WindowDiff;
MainWindow1.高度=旧窗口高度;
MainWindow1.MinHeight=旧窗口高度;
}
//MainWindow1.MinHeight=220;
}
if(CheckBoxSetup.IsChecked==true&&CheckBoxUpdate.IsChecked==true)
{
MainWindow1.MinHeight=50;
OldWindowHeight=MainWindow1.高度;
int NewWindowHeigth=260;
WindowDiff=新窗高-旧窗高;
WindowDiff=WindowDiff/30;
对于(int a=0;a<30;a++)
{
OldWindowHeight=OldWindowHeight+WindowDiff;
MainWindow1.高度=旧窗口高度;
MainWindow1.MinHeight=旧窗口高度;
}
//MainWindow1.MinHeight=260;
}
if(CheckBoxSetup.IsChecked==true)
{
LabelDestinationSetup.Visibility=可见性.Visibility;
TextBoxDestinationpathSetup.Visibility=可见性.Visibility;
CheckCountSetup++;
}
其他的
{
LabelDestinationSetup.Visibility=可见性.Hidden;
TextBoxDestinationpathSetup.Visibility=可见性.Hidden;
检查计数设置--;
}
如果(CheckCountSetup==1)
{
LabelDestinationSetup.Margin=新厚度(24,thickTop1,0,0);
TextBoxDestinationpathSetup.Margin=新厚度(160,thickTop1,0,0);
LabelDestinationUpdatepackage.Margin=新厚度(24,厚度TOP2,0,0);
TextBoxDestinationpathUpdatePackage.Margin=新厚度(160,厚度TOP2,0,0);
}
如果(CheckCountSetup==0&&CheckCountUpdate==1)
{
LabelDestinationSetup.Margin=新厚度(24,thickTop2,0,0);
TextBoxDestinationpathSetup.Margin=新厚度(160,thickTop2,0,0);
LabelDestinationUpdatepackage.Margin=新厚度(24,厚度TOP1,0,0);
TextBoxDestinationpathUpdatePackage.Margin=新厚度(160,厚度TOP1,0,0);
}
如果(CheckCountSetup==0)
{
LabelDestinationSetup.Margin=新厚度(24,thickTop2,0,0);
TextBoxDestinationpathSetup.Margin=新厚度(160,thickTop2,0,0);
LabelDestinationUpdatepackage.Margin=新厚度(24,厚度TOP1,0,0);
TextBoxDestinationpathUpdatePackage.Margin=新厚度(160,厚度TOP1,0,0);
}   
}
私有无效复选框更新\单击(对象发送者,路由目标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.高度;
int NewWindowHeigth=180;
WindowDiff=新窗高-旧窗高;
WindowDiff=WindowDiff/30;
对于(int a=0;a<30;a++)
{
OldWindowHeight=OldWindowHeight+WindowDiff;
MainWindow1.高度=旧窗口高度;
MainWindow1.MinHeight=旧窗口高度;
}
//MainWindow1.MinHeight=180;
}
if(CheckBoxSetup.IsChecked==true | | CheckBoxUpdate.IsChecked==true)
{
MainWindow1.MinHeight=50;
OldWindowHeight=MainWindow1.高度;
int NewWindowHeigth=220;
WindowDiff=新窗高-旧窗高;
WindowDiff=WindowDiff/30;
对于(int a=0;a<30;a++)
{
OldWindowHeight=OldWindowHeight+WindowDiff;
MainWindow1.高度=旧窗口高度;
MainWindow1.MinHeight=旧窗口高度;
}
//MainWindow1.MinHeight=220;
}
if(CheckBoxSetup.IsChecked==true&&CheckBoxUpdate.IsChecked==true)
{
MainWindow1.MinHeight=50;
OldWindowHeight=MainWindow1.高度;
int NewWindowHeigth=260;
WindowDiff=新窗高-旧窗高;
WindowDiff=WindowDiff/30;
对于(int a=0;a<30;a++)
{
OldWindowHeight=OldWindowHeight+WindowDiff;
MainWindow1.高度=旧窗口高度;
MainWindow1.MinHeight=旧窗口高度;
}
//MainWindow1.MinHeight=260;
}
if(CheckBoxUpdate.IsChecked==true)
{
LabelDestinationUpdatepackage.Visibility=可见性.Visibility;
TextBoxDestinationpathUpdatePackage.Visibility=可见性.Visibility;
CheckCountUpdate++;
}
其他的
{
LabelDestinationUpdatepackage.Visibility=可见性.Hidden;
TextBoxDestinationpathUpdatePackage.Visibility
<Window x:Class=.........
        DataContext="{StaticResource MainViewModel}"
        Name="MyWindow"
        >

    <Window.Triggers >
        <EventTrigger  RoutedEvent="CheckBox.Unchecked" >
            <BeginStoryboard  >
                <Storyboard   >
                    <DoubleAnimation  Storyboard.TargetName="MyWindow" Storyboard.TargetProperty = "(Window.Height)" Duration="0:0:0.5" To="{Binding WindowHeight}"  RepeatBehavior="1x" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
        <EventTrigger  RoutedEvent="CheckBox.Checked"  >
            <BeginStoryboard  >
                <Storyboard   >
                    <DoubleAnimation  Storyboard.TargetName="MyWindow" Storyboard.TargetProperty = "(Window.Height)" Duration="0:0:0.5" To="{Binding WindowHeight}"  RepeatBehavior="1x" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Window.Triggers>

    <Grid Row="0" >
        ............
        <CheckBox   Grid.Column="4" 
                    Content="UpadatePack" 
                    IsChecked="{Binding PackegeCheck, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" 
                    Name="CheckUpadatePack" />
        <CheckBox   Grid.Column="5" 
                    Content="Setup" 
                    IsChecked="{Binding SetupCheck, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" 
                    Name="CheckSetup"  />
        ...... 
    </Grid>
    <Grid Row="5" Visibility="{Binding SetupDestinationVisibility, Converter={StaticResource BoolToVisibilityConverter}}" >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="120"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Label Content="Setup Destination" Margin="5" Grid.Column="0"/>
        <TextBox  Margin="5" Grid.Column="1"/>
    </Grid>
    <Grid Row="6" Visibility="{Binding PackageDestinationVisibility, Converter={StaticResource BoolToVisibilityConverter}}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="120"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Label Content="Package Destination" Margin="5" Grid.Column="0"/>
        <TextBox  Margin="5" Grid.Column="1"/>
    </Grid>

</Window>
public class MainViewModel : ViewModelBase
{

    private bool _sixtyFourBitCheck;
    private bool _packegeCheck;
    private bool _setupCheck;
    private bool _ftpUploadCheck;
    public int _windowHeight;
    public int _origSize = 200;


    public bool SixtyFourBitCheck
    {
        get => _sixtyFourBitCheck;
        set
        {
            if (value == _sixtyFourBitCheck) return;
            _sixtyFourBitCheck = value;
            OnPropertyChanged();
        }
    }

    public bool PackegeCheck
    {
        get => _packegeCheck;
        set
        {
            if (value == _packegeCheck) return;
            _packegeCheck = value;
            OnPropertyChanged();
            OnPropertyChanged(nameof(PackageDestinationVisibility));
            ChangeWindowsHeght();
        }
    }

    public bool SetupCheck
    {
        get => _setupCheck;
        set
        {
            if (value == _setupCheck) return;
            _setupCheck = value;
            OnPropertyChanged();
            OnPropertyChanged(nameof(SetupDestinationVisibility));
            ChangeWindowsHeght();
        }
    }

    public bool FtpUploadCheck
    {
        get => _ftpUploadCheck;
        set
        {
            if (value == _ftpUploadCheck) return;
            _ftpUploadCheck = value;
            OnPropertyChanged();
        }
    }

    public bool SetupDestinationVisibility => SetupCheck;

    public bool PackageDestinationVisibility => PackegeCheck;

    public int WindowHeight
    {
        get => _windowHeight;
        set
        {
            if (value == _windowHeight) return;
            _windowHeight = value;
            OnPropertyChanged();
        }
    }

    public MainViewModel()
    {
        WindowHeight = _origSize;
    }

    private void ChangeWindowsHeght()
    {
        WindowHeight = _origSize;
        if (PackageDestinationVisibility)
            WindowHeight += 35;
        if (SetupDestinationVisibility)
            WindowHeight += 35;
        OnPropertyChanged(nameof(WindowHeight));
    }
}