簡體   English   中英

我想在C#中的WPF中制作動態窗口內容(img&font&frame)的大小

[英]I want make Dynamic window content(img&font&frame) size in WPF at c#

在此處輸入圖片說明

在此處輸入圖片說明

我想以1024 * 768的窗口大小和內容大小的比率填充監視器的全屏。

在寬顯示器的Fill Blank Right Left Area用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>

如果我理解正確,那么您需要做的就是用Viewbox包裝Window元素的內容。 這是示例代碼,在我擁有的每個元素中,我只編寫了重要的部分,其他可以根據需要設置:

<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_Out Grid中設置的任何值)為內容未覆蓋的區域設置背景色。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM