我想用1024 * 768比例的窗口大小填充显示器的全屏。内容大小。
在宽显示器的填充空白右侧区域使用时填充黑色白色使用x:Name =“wide_Out” 我怎样才能制作动态全画面窗口&无论显示器分辨率和类型如何,内容(保持主赢大小率)。
mainwindow.xaml
<Window x:Class="C.MainWindow"
xmlns:local="clr-namespace:M_C"
mc:Ignorable="d"
Title="MainWindow" Height="768" Width="1024" WindowStyle="None">
<Grid x:Name="wide_Out" Margin="0,0,0,0">
<Grid Height="768" Width="1024">
<DockPanel x:Name="L_black" HorizontalAlignment="Left" Height="737"
LastChildFill="False" VerticalAlignment="Top" Width="62"
Background="#FF242424">
<Button Margin="15,8,0,0" Height="40" VerticalAlignment="Top"
Width="30"/>
</DockPanel>
<DockPanel x:Name="T_blue" HorizontalAlignment="Left" Height="100"
LastChildFill="False" Margin="62,0,0,0" VerticalAlignment="Top"
Width="954" Background="#FF248BC7">
<TextBlock Margin="200,10,200,0" Height="80"
TextWrapping="Wrap"
Text="TextBlock" VerticalAlignment="Top" Width="554"/>
</DockPanel>
<DockPanel x:Name="L_blue" HorizontalAlignment="Left" Height="637"
LastChildFill="False" Margin="62,100,0,0" VerticalAlignment="Top"
Width="82" Background="#FF248BC7"/>
<DockPanel x:Name="R_blue" HorizontalAlignment="Left" Height="637"
LastChildFill="False" Margin="934,100,0,0" Background="#FF248BC7"
Width="82"/>
<DockPanel x:Name="B_blue" HorizontalAlignment="Left" Height="100"
LastChildFill="False" Margin="144,637,0,0" VerticalAlignment="Top"
Width="790" Background="#FF248BC7">
<Image Margin="250,15,250,15" Height="70"
VerticalAlignment="Top" Width="290" />
</DockPanel>
<DockPanel x:Name="main_content_panel" HorizontalAlignment="Left"
Height="537" LastChildFill="False" Margin="144,100,0,0"
VerticalAlignment="Top" Width="790">
<Grid Margin="0,0,0,0">
</Grid>
</DockPanel>
</Grid>
</Grid>
</Window>
答案 0 :(得分:1)
如果我理解正确,您需要做的是用Window
包裹Viewbox
元素的内容。这是示例代码,从我拥有的每个元素,我只写了重要的部分,其他可以根据需要设置:
<Window
Height="{x:Static SystemParameters.PrimaryScreenHeight}"
Width="{x:Static SystemParameters.PrimaryScreenWidth}" <!--To set your window size to the size of monitor-->
WindowStyle="None" <!--To not display any controls-->
>
<Viewbox> <!--You can try using different 'Stretch' attribute values-->
<Grid Width="768" Height="1024" x:Name="wide_Out"> <!--Or whatever dimensions you want your 'base' window to work with-->
<DockPanel x:Name="L_black" HorizontalAlignment="Left" Height="737" LastChildFill="False" VerticalAlignment="Top" Width="62" Background="#FF242424">
<Button Margin="15,8,0,0" Height="40" VerticalAlignment="Top" Width="30"/>
</DockPanel>
<DockPanel x:Name="T_blue" HorizontalAlignment="Left" Height="100" LastChildFill="False" Margin="62,0,0,0" VerticalAlignment="Top" Width="954" Background="#FF248BC7">
<TextBlock Margin="200,10,200,0" Height="80" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="554"/>
</DockPanel>
<DockPanel x:Name="L_blue" HorizontalAlignment="Left" Height="637" LastChildFill="False" Margin="62,100,0,0" VerticalAlignment="Top" Width="82" Background="#FF248BC7"/>
<DockPanel x:Name="R_blue" HorizontalAlignment="Left" Height="637" LastChildFill="False" Margin="934,100,0,0" Background="#FF248BC7" Width="82"/>
<DockPanel x:Name="B_blue" HorizontalAlignment="Left" Height="100" LastChildFill="False" Margin="144,637,0,0" VerticalAlignment="Top" Width="790" Background="#FF248BC7">
<Image Margin="250,15,250,15" Height="70" VerticalAlignment="Top" Width="290" />
</DockPanel>
<DockPanel x:Name="main_content_panel" HorizontalAlignment="Left" Height="537" LastChildFill="False" Margin="144,100,0,0" VerticalAlignment="Top" Width="790">
<Grid Margin="0,0,0,0">
</Grid>
</DockPanel>
</Grid>
</Viewbox>
</Window>
重要的部分是窗口宽度和高度,视图框元素,然后是wide_Out
网格的实际宽度和高度,在设置内部尺寸和边距时,您将使用它。
如果您愿意,可以使用窗口的BackgroundColor
属性为屏幕的宽高比不是4:3(或者您设置的任何内容)设置内容未覆盖的区域的背景颜色`wide_Out Grid)。