2016-09-06 78 views
0

我刚刚从WinForms切换到WPF今天。
我现在面临的问题是,在某个点之后,当我运行应用程序(在设计器中我看到所有内容)时,下面的所有内容都会被切断。WPF窗体切断一切点下面的所有内容

宽度为1920,高度为1080我使用WindowState="Maximized",也许这是为什么呢?

我想创建一个应用程序,全屏,但再次 - 某一点后,下面一切都被切断,当我运行应用程序 我只是想将它们放在哪里,并为他们留没有什么特别的。那么,也许不需要“网格”?
这里的XMAL代码:

<Window x:Class="KodeOS.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:KodeOS" 
    mc:Ignorable="d" 
    Title="KodeOS" Height="1080" Width="1920" WindowStartupLocation="CenterScreen" WindowState="Maximized" WindowStyle="None"> 
<Grid> 
    <Grid.Background> 
     <ImageBrush ImageSource="pack://siteoforigin:,,,/Resources/kdroid_wallpaper1.png"/> 
    </Grid.Background> 
    <Label x:Name="label" Content="KodeOS" HorizontalAlignment="Left" VerticalAlignment="Top" FontFamily="Segoe Print" FontSize="18.667" Margin="10,0,0,0" Foreground="White"/> 
    <Label x:Name="label1" Content="by Kamil" HorizontalAlignment="Left" Margin="10,24,0,0" VerticalAlignment="Top" FontFamily="Segoe Print" Foreground="White"/> 
    <Button x:Name="button" Content="After here everything will be cut off" HorizontalAlignment="Left" Margin="18,665,0,0" VerticalAlignment="Top" Width="255" RenderTransformOrigin="0.526,-0.807" Height="44"/> 
    <Button x:Name="button_Copy" Content="I'm past the cut off zone" HorizontalAlignment="Left" Margin="37,814,0,0" VerticalAlignment="Top" Width="179" RenderTransformOrigin="0.526,-0.807" Height="30"/> 

</Grid> 

+0

[这个简单的教程可能有帮助](http://www.wpf-tutorial.com/panels/grid/) – nabulke

+0

@nabulke我不认为添加网格将有所帮助。也许你可以尝试运行它,看看问题是什么?它也感觉像控制(按钮,标签等)的位置可能比我在设计师看到的更低? – Kamdroid

+0

你已经在你的例子中_had_ a'Grid'。链接解释了如何正确使用它,以及为什么它现在产生错误的结果。 – nabulke

回答

0

我看不出有任何Grid.RowGrid.Column分配给您的控件,如标签或按钮。网格系统有点像Winform中的表格布局。

通常以网格布局,你不需要对准RenderTransformOrigin,Margns和垂直/水平对齐,只是建立一个适当的网格布局应该做的元素。

您将您的元素(按钮,标签等)放入网格控件中。网格控件的工作方式是基于与这些元素相关联的列/行值来排列所有项目,例如,将标签放入行= 0,列= 0,将按钮放入行= 0,列= 1)。如果您省略这些值,则将使用默认的行/列,其为零。

这意味着,所有的元素将基本上重叠,但你已经成功地把它们彼此相距基于其他间隔属性,如保证金/填充等,这是不是要走的路。

+0

我不太明白。为什么我需要为我的控件分配'Grid.Row' /'Grid.Column'?如何?我还没有在Winform中使用表格布局。 – Kamdroid

+1

@Kamdroid澄清了答案,看看是否有帮助。这是基本的WPF布局系统,如果你不熟悉,我建议阅读一本书(或使用其他资源在你的处置),因为它不完全像WinForms。 –

1

基本上你不通过定义边距对齐网格内容 - 你需要专门的行和列分配给你的标签/按钮/无论

例如,这段代码

<Grid Background="Gray"> 
    <Grid.RowDefinitions> 
     <RowDefinition></RowDefinition> 
     <RowDefinition></RowDefinition> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="Auto"></ColumnDefinition> 
     <ColumnDefinition Width="Auto"></ColumnDefinition> 
    </Grid.ColumnDefinitions> 

    <Label x:Name="label" Grid.Column="0" Grid.Row="0" Content="KodeOS" HorizontalAlignment="Left" VerticalAlignment="Top" FontFamily="Segoe Print" FontSize="18.667" Foreground="White"/> 
    <Label x:Name="label1" Grid.Column="1" Grid.Row="0" Content="by Kamil" HorizontalAlignment="Left" VerticalAlignment="Top" FontFamily="Segoe Print" Foreground="White"/> 
    <Button x:Name="button" Grid.Column="0" Grid.Row="1" Content="After here everything will be cut off" HorizontalAlignment="Left" VerticalAlignment="Top" Width="255" Margin="5" Height="44"/> 
    <Button x:Name="button_Copy" Grid.Column="1" Grid.Row="1" Content="I'm past the cut off zone" HorizontalAlignment="Left" VerticalAlignment="Top" Width="179" Margin="5" Height="30"/> 

</Grid> 

会导致这样的布局: enter image description here

如果你想手动放置你的对象,你可以使用Canvas容器,你能在那里将内容与Canvas.Left' and Canvas.Top`

例如:

<Canvas Background="Gray"> 

    <Label x:Name="label" Canvas.Left="25" Canvas.Top="5" Content="KodeOS" HorizontalAlignment="Left" VerticalAlignment="Top" FontFamily="Segoe Print" FontSize="18.667" Foreground="White"/> 
    <Label x:Name="label1" Canvas.Left="55" Canvas.Top="55" Content="by Kamil" HorizontalAlignment="Left" VerticalAlignment="Top" FontFamily="Segoe Print" Foreground="White"/> 
    <Button x:Name="button" Canvas.Left="75" Canvas.Top="125" Content="After here everything will be cut off" HorizontalAlignment="Left" VerticalAlignment="Top" Width="255" Margin="5" Height="44"/> 
    <Button x:Name="button_Copy" Canvas.Left="125" Canvas.Top="205" Content="I'm past the cut off zone" HorizontalAlignment="Left" VerticalAlignment="Top" Width="179" Margin="5" Height="30"/> 

</Canvas> 

会变成这样: enter image description here

不过一般我不会去说,因为你不能在窗口动态响应 - 大小变化

+0

谢谢,但我打算将其创建为全屏(最大化)的WPF应用程序。我不需要以任何特殊的方式来定位控件,我只是想把它们放在任何地方,让它们留在那里。高度为1080,宽度为1920(我的屏幕分辨率),窗口状态最大化。在设计师中,一切都看起来不错,但是当我运行任何低于某点的东西时,它会被切断,任何帮助? – Kamdroid

+0

如果只有你会使用该程序,那没关系。但如果其他人使用它,他们的解析度甚至可能达到800x600,然后他们甚至不会看到你的窗口的一半。 – mcy