时设置窗口最大化
我是新与WPF形式所以这可能很容易,但如何调整所有对象的我的WPF形式...时设置窗口最大化
我创建了一个新的WPF的形式,并添加12图像。我设定了最大化的窗口,我相信它可以适用于任何显示器上的视图,对吧?如何让我的对象转换,以便在最大化模式下看起来大致相同?
第一张图片是设计师看起来像的样子,第二张是程序运行时的样子。
显然,你要舒展你的整个UI。然后ViewBox控件是非常有用的:
<Window ...>
<ViewBox>
<Grid Height="800" Width="600">
<!-- Everything inside viewbox will be stretched as you resize window
Place you UI assuming you have virtual resolution 800x600 -->
</Grid>
</ViewBox>
</Window>
我建议你使用WrapPanel来布置你的图片:
<WrapPanel>
<Image x:Name="b1" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Source="blackCircle.png" Visibility="Hidden"/>
<Image x:Name="b2" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Source="blackCircle.png"/>
<Image x:Name="b4" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Source="blackCircle.png"/>
<Image x:Name="b3" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Source="blackCircle.png" Visibility="Hidden"/>
<Image x:Name="b5" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Source="blackCircle.png" Visibility="Hidden"/>
<Image x:Name="b6" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Source="blackCircle.png"/>
<Image x:Name="y1" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="51" Source="yellowCircle.png"/>
<Image x:Name="y2" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="51" Source="yellowCircle.png" Visibility="Hidden"/>
<Image x:Name="y3" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="51" Source="yellowCircle.png"/>
<Image x:Name="y4" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Source="yellowCircle.png" Visibility="Hidden"/>
<Image x:Name="y5" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Source="yellowCircle.png"/>
<Image x:Name="y6" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Source="yellowCircle.png" Visibility="Hidden"/>
</WrapPanel>
WrapPanel
如果没有没有足够的空间自动换到新的生产线。
更新:
我做了一个测试5张图片,但您可以12张图像做。要做12张图片,你应该添加12列。让我给个例子:
<Window x:Class="SOWpfApplication.MainWindow"
<!--The code omitted for the brevity-->
>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="2*"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Image Source="/Images/Back.jpg" Stretch="UniformToFill"/>
<Image Source="/Images/Forward.jpg" Grid.Column="1" Stretch="UniformToFill"/>
<Image Source="/Images/Back.jpg" Grid.Column="2" Stretch="UniformToFill"/>
<Image Source="/Images/Back.jpg" Grid.Column="3" Stretch="UniformToFill"/>
<Image Source="/Images/Forward.jpg" Grid.Column="4" Stretch="UniformToFill"/>
</Grid>
<TextBlock Text="Time is up!" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="50"/>
<Button Margin="10" Grid.Row="2" HorizontalAlignment="Left" Height="42" Width="150" Content="Close" />
</Grid>
</Window>
我最常做的是要扩大,对顶部和右侧选择锚,因为这通常是足够的伸展我的目的部分的编辑。然而,随着锚的发挥,这是什么会让你缩放你正在寻找。在你的情况下,你可能想要锚定你想缩放的所有东西的所有四个方面。
编辑
或者,你也可以选择绵延水平和垂直对齐,这将导致拉伸为好。请注意,只要确保使用边距将图像放置在所需的位置即可。
如果你想扩展一切(看起来更大,以适应屏幕),你可以使用' ViewBox'。 – mechanic
尝试设置高度&宽度属性为“自动”,这将自动调整窗体上的所有元素。
问候, 维沙尔
这并没有解决我遇到的问题。我会看看我是否可以为我的问题添加屏幕截图。 –
我编辑了我原来的问题。我修正了第二部分。 –
@NotSteve请参阅我的更新部分 – StepUp