Reputation: 9
I want to fill the monitor's full screen with 1024*768 ratio of window size& content size.
When use at wide monitor's Fill Blank Right Left Area fill black color whit use x:Name="wide_Out" how can I make dynamic Full screan window & contents (keep main win size rate), regardless of monitor resolution and type.
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>
Upvotes: 0
Views: 1016
Reputation: 449
If I understand you correctly, what you need to do is wrap the content of your Window
element with a Viewbox
. Here is sample code, from every element I have I have only written the parts that are important, other may be set as needed:
<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>
The important parts are the window width and height, the viewbox element and then the actual width and height of the wide_Out
Grid, with which you will work when setting inner dimensions and margins.
If you want to, you can use BackgroundColor
attribute of the window to set background color for the area that is not covered by your content when screen's aspect ratio is other than 4:3 (or whatever you set in `wide_Out Grid).
Upvotes: 1