当我伸展窗户时,底部元素消失了

时间:2017-04-20 14:05:40

标签: c# wpf

我正在做一些项目,我有拉伸窗户的问题。当我这样做时,stackpanel中的最后元素消失了。我有一个主StackPanel,里面有更多的Grids和StackPanel。 我将发布一个关于我的问题的5秒视频,如果有人需要,我也可以发布代码。

------VIDEO------

这是我的代码:

<Window x:Class="BookReader2017.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:BookReader2017"
    mc:Ignorable="d"
    Title="MainWindow" Height="800" Width="525"
    WindowStartupLocation = "CenterScreen">


<Border Padding="10" Background="#2d2d30" Margin="0,0,0,0">


    <StackPanel Name="StackMenu">


            <Grid>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition MinWidth="110"/>
                    <ColumnDefinition Width="10"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="3*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>

                <Image Width="100" HorizontalAlignment="Left" Source="BrImages/logo.png" Grid.Column="0" />

                <Border Grid.Column="2" >
                    <Border.Effect>
                        <DropShadowEffect BlurRadius="25"/>
                    </Border.Effect>

                    <Button x:Name="Button1" BorderBrush="#3db1ff" BorderThickness="0 0 0 3" Margin="2 2 2 2"  Background="#007acc" Foreground="white">
                        <StackPanel>
                            <Image Source="BrImages/open.png" Width="50" Height="30"/>
                            <TextBlock Text="Open" HorizontalAlignment="Center" />
                        </StackPanel>
                    </Button>

                </Border>

                <Border Grid.Column="3">
                    <Border.Effect>
                        <DropShadowEffect BlurRadius="25"/>
                    </Border.Effect>
                    <Button x:Name="Button2" BorderBrush="#3db1ff" BorderThickness="0 0 0 3" Margin="2 2 2 2"  Background="#007acc" Foreground="white">
                        <StackPanel>
                            <Image Source="BrImages/settings.png" Width="50" Height="30"/>
                            <TextBlock Text="Settings" HorizontalAlignment="Center" />
                        </StackPanel>
                    </Button>
                </Border>

                <Border Grid.Column="4">
                    <Border.Effect>
                        <DropShadowEffect BlurRadius="25"/>
                    </Border.Effect>
                    <Button x:Name="Button3" Click="Button3_Click" BorderBrush="#3db1ff" BorderThickness="0 0 0 3" Margin="2 2 2 2" Background="#007acc" Foreground="white">
                        <StackPanel>
                            <Image Source="BrImages/fullscreen.png" Width="50" Height="30"/>
                            <TextBlock Text="Fullscreen" HorizontalAlignment="Center" />
                        </StackPanel>
                    </Button>
                </Border>

                <Border Grid.Column="5">
                    <Border.Effect>
                        <DropShadowEffect BlurRadius="25"/>
                    </Border.Effect>
                    <Button x:Name="Button4" Click="Button4_Click" BorderBrush="#3db1ff" BorderThickness="0 0 0 3" Margin="2 2 2 2"  Grid.Column="4" Background="#007acc" Foreground="white">
                        <StackPanel>
                            <Image Source="BrImages/about.png" Width="50" Height="30"/>
                            <TextBlock Text="About" HorizontalAlignment="Center" />
                        </StackPanel>
                    </Button>
                </Border>

                <Border Grid.Column="7">
                    <Border.Effect>
                        <DropShadowEffect BlurRadius="25"/>
                    </Border.Effect>
                    <Button x:Name="Button5" BorderBrush="#ff95b2" BorderThickness="0 0 0 3" Margin="2 2 2 2" Background="#b81d47" Foreground="white">
                        <StackPanel>
                            <Image Source="BrImages/exit.png" Width="50" Height="30"/>
                            <TextBlock Text="Exit" HorizontalAlignment="Center" />
                        </StackPanel>
                    </Button>
                </Border>


            </Grid>

            <Separator Background="#1e1e1e" Margin="0,10,0,10"/>


            <FlowDocumentReader Height="Auto" Margin="0 0 0 0" Foreground="white" Background="#007acc">
                <FlowDocument Background="#1e1e1e">

                </FlowDocument>
            </FlowDocumentReader>

            <TextBlock Text="BookReader 2017" TextAlignment="Center"/>

        </StackPanel>

</Border>

1 个答案:

答案 0 :(得分:0)

我想我明白了。我删除了主StackPanel并将所有内容放入DockPanel,然后我就停靠了网格。我想现在这是一个很好的解决方案。