图像大小到窗口,但不是图像窗口

时间:2013-06-27 19:14:18

标签: wpf xaml layout

我一直在研究如何进行布局,而且我遇到了一些困扰我的事情。现在,如果我使用下面的代码,那么窗口将占据整个屏幕。

<Window x:Class="HDD_Drill_View.Windows.WndwMain"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="HDDC"
        WindowStartupLocation="CenterScreen"
        Name="wndwMain"
        Closing="WindowClosing"
        ResizeMode="NoResize"
        WindowState="Normal"
        SizeToContent="WidthAndHeight">
    <Grid>
        <DockPanel Width="Auto"
                   LastChildFill="False"
                   HorizontalAlignment="Left">
            <DockPanel.Background>
                <ImageBrush ImageSource="..\Resources\background.png"
                            Stretch="UniformToFill"
                            TileMode="None" />
            </DockPanel.Background>
            <StackPanel DockPanel.Dock="Top"
                        Height="Auto"
                        Width="Auto"
                        Orientation="Horizontal"
                        HorizontalAlignment="Center">
                <Button HorizontalAlignment="Left"
                        Name="bttnGenerateReports"
                        VerticalAlignment="Top"
                        UseLayoutRounding="False"
                        Click="BttnGenerateReportsClick"
                        Margin="10">
                    <TextBlock HorizontalAlignment="Center"
                               VerticalAlignment="Center"><Run Text="Generate" /><LineBreak /><Run Text=" Reports" /></TextBlock>
                </Button>

                <Button HorizontalAlignment="Left"
                    Name="bttnSurveyReport"
                    VerticalAlignment="Top"
                    UseLayoutRounding="False"
                    Click="BttnSurveyReportClick"
                    Margin="10">
                <TextBlock HorizontalAlignment="Center"
                           VerticalAlignment="Center"><Run Text="Survey" /><LineBreak /><Run Text="Report" /></TextBlock>
            </Button>

            <Button HorizontalAlignment="Left"
                    Name="bttnTimeChart"
                    VerticalAlignment="Top"
                    UseLayoutRounding="False"
                    Click="BttnTimeChartClick"
                    Margin="10">
                <TextBlock HorizontalAlignment="Center"
                           VerticalAlignment="Center"><Run Text=" Time" /><LineBreak /><Run Text=" Chart" /></TextBlock>
            </Button>

            <Button HorizontalAlignment="Left"
                    Name="bttnMaterialAcquisition"
                    VerticalAlignment="Top"
                    UseLayoutRounding="False"
                    Click="BttnMaterialAcquisitionClick"
                    Margin="10">
                <TextBlock HorizontalAlignment="Center"
                           VerticalAlignment="Center"><Run Text="  Material" /><LineBreak /><Run Text="Acquistion" /></TextBlock>
            </Button>
        </StackPanel>

        <StackPanel DockPanel.Dock="Bottom"
                    Height="Auto"
                    Width="Auto"
                    Orientation="Horizontal">
                    <!--MaxWidth="800"
                    MaxHeight="80"--> 
            <StackPanel.Background>
                <ImageBrush ImageSource="..\Resources\drildata2.jpg" />
            </StackPanel.Background>
        </StackPanel>
    </DockPanel>
    </Grid>
</Window>

然而,如果我取消注释上一个Max Height中的Max WidthStackPanel,那么它似乎没问题。基本上,我希望我的背景图像不会影响我的窗口大小。这可能吗?我试图将StackPanel的背景设置为图像。

1 个答案:

答案 0 :(得分:0)

从窗口中删除SizeToContent="WidthAndHeight"