代码之家  ›  专栏  ›  技术社区  ›  Jin_Jin

我想使动态窗口内容(img&字体和框架)的大小在WPF在c#

  •  0
  • Jin_Jin  · 技术社区  · 8 年前

    enter image description here

    enter image description here

    我想用1024*768的窗口大小和;内容大小。

    当在宽监视器的填充空白左右区域填充黑色时,使用x:Name=“wide\u Out” 如何制作动态全屏幕窗口&内容(保持主窗口大小速率),无论监视器分辨率和类型如何。

    <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>
    
    1 回复  |  直到 8 年前
        1
  •  1
  •   Michal KrejÄí    8 年前

    如果我理解正确,您需要做的是包装 Window 带a的元素 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>
    

    重要的部分是窗口宽度和高度、viewbox元素,然后是窗口的实际宽度和高度 wide_Out 网格,用于设置内部尺寸和边距。

    如果你想,你可以使用 BackgroundColor 属性设置当屏幕的纵横比不是4:3(或在“wide\u Out Grid”中设置的任何值)时内容未覆盖的区域的背景色。