本文介绍了需要具有较低分辨率的图像“拉伸”屏幕大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在使用C#WPF制作视频游戏。 我现在想要实现的是增加额外的分辨率。 我的默认显示器分辨率为1600x900。 我为游戏的窗口和网格使用了相同的大小。 现在,我想添加更多的分辨率。我已经找到了一种简单的方法来改变代码中的值,问题在于另一个主题。 这就是游戏在1600x900上的样子。 然后,我试图设置800x600的分辨率。 我想要实现的目标是使图像的分辨率低于Windows中设置的分辨率,以获得延伸并仍覆盖全屏。 这就是我得到的。游戏只占用屏幕的一部分,其余部分使用白色背景。 拉伸的窗口,我试图实现的是这样的。为了创建这个图像,我在图形编辑器中拉伸了以前的图像。我想让游戏自己做。 如果您以全尺寸查看第一屏和第三屏,您会注意到它们不同,而较低的图像有更糟的细节。 窗口或网格如何在Windows中的分辨率降低,但仍然覆盖全屏? UPDATE:其中一个游戏屏幕的代码 - 主菜单 < Grid x: Name =areaMenuPanel.ZIndex =1010Horizo​​ntalAlignment =LeftHeight =786Margin =0,-813,0,0VerticalAlignment =TopWidth =1366IsVisibleChanged =areaMenu_IsVisibleChanged> ; < Grid.Background> < ImageBrush ImageSource =Resources / Images / Interface / Main Menu / Menu_main.jpg/> < /Grid.Background> < Grid.RowDefinitions> < RowDefinition /> < RowDefinition Height =0 */> < /Grid.RowDefinitions> < Grid x:Name =areaLoadPanel.ZIndex =1011Horizo​​ntalAlignment =LeftHeight =245Margin =11,-556,0,0VerticalAlignment =TopWidth = 1340IsVisibleChanged =areaLoad_IsVisibleChanged> < Grid.Background> < ImageBrush ImageSource =Resources / Images / Interface / Main Menu / img_Load_Game.jpgStretch =Uniform/> < /Grid.Background> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < / Grid> < Grid x:Name =areaSavePanel.ZIndex =1011Horizo​​ntalAlignment =LeftHeight =245Margin =11,-285,0,0VerticalAlignment =TopWidth = 1340IsVisibleChanged =areaSave_IsVisibleChanged> < Grid.Background> < ImageBrush ImageSource =资源/图像/接口/主菜单/ img_Save_Game.jpgStretch =Uniform/> < /Grid.Background> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < / Grid> < Image x:Name =imgQuitHorizo​​ntalAlignment =LeftHeight =215Margin =469,587,0,-11VerticalAlignment =TopWidth =383Source =Resources / Images / Interface / Main Menu / Menu_quit.pngGrid.RowSpan =2/> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < MediaElement x:Name =musTheme3Panel.ZIndex =1001Horizo​​ntalAlignment =LeftHeight =47Margin =1290,21,0,0VerticalAlignment =TopWidth = 50Source =Resources / Music / theme_3.wavLoadedBehavior =ManualRenderTransformOrigin =3.464,0.571MediaOpened =AnySoundStartMediaEnded =musTheme3_MediaEnded/> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < Grid x:Name =areaGameSavedPanel.ZIndex =1011Horizo​​ntalAlignment =LeftHeight =245Margin =11,-839,0,0VerticalAlignment =TopWidth = 1340IsVisibleChanged =areaLoad_IsVisibleChanged> < Grid.Background> < ImageBrush ImageSource =资源/图像/接口/主菜单/ img_GAME_SAVED.jpgStretch =Uniform/> < /Grid.Background> < Image x:Name =imgBackSavedHorizo​​ntalAlignment =LeftHeight =215Margin =478,76,0,-53VerticalAlignment =TopWidth =383Source =Resources / Images / Interface / Main Menu / img_back.png/> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < / Grid> < Grid x:Name =areaNotAvailablePanel.ZIndex =1011Horizo​​ntalAlignment =LeftHeight =245Margin =11,-1114,0,0VerticalAlignment =TopWidth = 1340IsVisibleChanged =areaLoad_IsVisibleChanged> < Grid.Background> < ImageBrush ImageSource =资源/图像/界面/主菜单/ img_NOT_AVAILABLE_YET.jpgStretch =Uniform/> < /Grid.Background> < Image x:Name =imgBackNotAvailableHorizo​​ntalAlignment =LeftHeight =215Margin =478,76,0,-53VerticalAlignment =TopWidth =383Source =Resources / Images / Interface / Main Menu / img_back.png/> < Button.Template> < ControlTemplate> < Image Source =Resources / Images / Interface / Blank.pngStretch =FillMargin =12,0,6,0/> < / ControlTemplate> < /Button.Template> < / Button> < / Grid> < / Grid> 开始时的Xaml: < Window xmlns =http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x =http:// schemas .microsoft.com / winfx / 2006 / xamlxmlns:d =http://schemas.microsoft.com/expression/blend/2008xmlns:mc =http://schemas.openxmlformats.org/markup-compatibility / 2006mc:Ignorable =dx:Name =wdwMainx:Class =RealityIncognita.MainWindow Height =900Width =1600ResizeMode =NoResizeWindowState =Maximised Cursor =CrossWindowStyle =NoneLoaded =wdwMain_Loaded> < Grid x:Name =areaContainerHorizo​​ntalAlignment =LeftHeight =900VerticalAlignment =TopWidth =1600> 现在的样子: 谢谢, Evgenie 解决方案只需从网格中移除Horizo​​ntalAlignment =LeftHeight =600VerticalAlignment =TopWidth =800,以便网格可以延伸至整个窗口, 如果您需要这些值,请在窗口中使用它 编辑:好​​的,我看到您要为网格内的每个元素(如按钮)设置高度和宽度,并且您将边距设置为将它们移动到正确的位置,这将不会t以不同的分辨率工作。可以说你将窗口宽度设置为800,并将按钮设置为200.如果将窗口宽度更改为1024,则此更改不会自动反映到按钮,它始终为200(对于边距也是一样) 正确的解决方案是以正确的方式重写xaml代码(您将使用Grid.ColumnsDefinition / RowDefinition,Stackpanels ..etc)而不设置以像素为单位。 但是,如果您很着急,可以将所有元素放入Viewbox中: < Window .... < Viewbox Stretch =Fill> < Grid x:Name =areaContainer.... < / Grid> < / Viewbox> < / Window> 现在请注意,使用viewbox会根据Viewbox的宽度和高度来扩展您的内容(所以它就像你在图形编辑器中做过)。 还要注意,应该避免使用Viewbox,因为它在资源方面非常昂贵 I am making a video game using C# WPF.What I am trying to implement now, is to add additional resolutions.My default monitor resolution is 1600x900.I am using the same size for game's window and grids.Now, I want to add more resolutions. I already found an easy way to change values in code, the problem is on another topic.That's how the game looks on 1600x900.Then, I am trying to set resolution 800x600.What I want to achieve, is to make images with resolution lower then the one set in Windows, to get "stretched" and still cover the all screen.That's what I get. The game only takes a part of the screen, and white background on the remaining part.The stretched window, what I am trying to achieve looks like that. To create this image I stretched the previous image in graphics editor. I want the game do it by itself.If you look at first and third screens at full size, you'll notice they are different, and that lower image has worse detail.How can the window or grid has resolution lower that one in Windows, but still cover full screen?UPDATE: Code for one of game screens - the main menu <Grid x:Name="areaMenu" Panel.ZIndex="1010" HorizontalAlignment="Left" Height="786" Margin="0,-813,0,0" VerticalAlignment="Top" Width="1366" IsVisibleChanged="areaMenu_IsVisibleChanged"> <Grid.Background> <ImageBrush ImageSource="Resources/Images/Interface/Main Menu/Menu_main.jpg"/> </Grid.Background> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition Height="0*"/> </Grid.RowDefinitions> <Grid x:Name="areaLoad" Panel.ZIndex="1011" HorizontalAlignment="Left" Height="245" Margin="11,-556,0,0" VerticalAlignment="Top" Width="1340" IsVisibleChanged="areaLoad_IsVisibleChanged"> <Grid.Background> <ImageBrush ImageSource="Resources/Images/Interface/Main Menu/img_Load_Game.jpg" Stretch="Uniform"/> </Grid.Background> <Button x:Name="btnLoad1" Panel.ZIndex="100" HorizontalAlignment="Left" Height="98" VerticalAlignment="Top" Width="170" Click="btnLoad1_Click" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" MouseEnter="btnInventory1_MouseEnter" MouseLeave="MouseLeaveAnyObject" Margin="45,133,0,0"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> <Button x:Name="btnLoad2" Panel.ZIndex="100" HorizontalAlignment="Left" Height="93" VerticalAlignment="Top" Width="166" Click="btnLoad2_Click" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" MouseEnter="btnInventory1_MouseEnter" MouseLeave="MouseLeaveAnyObject" Margin="263,133,0,0"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> <Button x:Name="btnLoad3" Panel.ZIndex="100" HorizontalAlignment="Left" Height="103" VerticalAlignment="Top" Width="170" Click="btnLoad3_Click" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" MouseEnter="btnInventory1_MouseEnter" MouseLeave="MouseLeaveAnyObject" Margin="480,133,0,0"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> <Image x:Name="imgLoad1" HorizontalAlignment="Left" Height="101" Margin="44,144,0,0" VerticalAlignment="Top" Width="172" Source="Resources/Images/Interface/default.bmp" Stretch="Fill"/> <Image x:Name="imgLoad2" HorizontalAlignment="Left" Height="101" Margin="262,132,0,0" VerticalAlignment="Top" Width="172" Source="Resources/Images/Interface/default.bmp" Stretch="Fill"/> <Image x:Name="imgLoad3" HorizontalAlignment="Left" Height="101" Margin="477,132,0,0" VerticalAlignment="Top" Width="172" Source="Resources/Images/Interface/default.bmp" Stretch="Fill"/> <Image x:Name="imgLoad4" HorizontalAlignment="Left" Height="101" Margin="694,132,0,0" VerticalAlignment="Top" Width="172" Source="Resources/Images/Interface/default.bmp" Stretch="Fill"/> <Image x:Name="imgLoad5" HorizontalAlignment="Left" Height="101" Margin="913,132,0,0" VerticalAlignment="Top" Width="172" Source="Resources/Images/Interface/default.bmp" Stretch="Fill"/> <Button x:Name="btnLoad4" Panel.ZIndex="100" HorizontalAlignment="Left" Height="103" VerticalAlignment="Top" Width="166" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" MouseEnter="btnInventory1_MouseEnter" MouseLeave="MouseLeaveAnyObject" Margin="695,133,0,0" Click="btnLoad4_Click"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> <Button x:Name="btnLoad5" Panel.ZIndex="100" HorizontalAlignment="Left" Height="98" VerticalAlignment="Top" Width="166" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" MouseEnter="btnInventory1_MouseEnter" MouseLeave="MouseLeaveAnyObject" Margin="914,133,0,0" Click="btnLoad5_Click"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> <Button x:Name="btnLoadCancel" Panel.ZIndex="100" HorizontalAlignment="Left" Height="86" VerticalAlignment="Top" Width="162" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" MouseEnter="btnInventory1_MouseEnter" MouseLeave="MouseLeaveAnyObject" Margin="1131,139,0,0" Click="btnLoadCancel_Click"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> </Grid> <Grid x:Name="areaSave" Panel.ZIndex="1011" HorizontalAlignment="Left" Height="245" Margin="11,-285,0,0" VerticalAlignment="Top" Width="1340" IsVisibleChanged="areaSave_IsVisibleChanged"> <Grid.Background> <ImageBrush ImageSource="Resources/Images/Interface/Main Menu/img_Save_Game.jpg" Stretch="Uniform"/> </Grid.Background> <Button x:Name="btnSaveEmpty1" Panel.ZIndex="100" HorizontalAlignment="Left" Height="93" VerticalAlignment="Top" Width="166" Click="btnSave1_Click" MouseEnter="btnInventory1_MouseEnter" MouseLeave="MouseLeaveAnyObject" Margin="47,133,0,0"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> <Button x:Name="btnSaveEmpty2" Panel.ZIndex="100" HorizontalAlignment="Left" Height="93" VerticalAlignment="Top" Width="159" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" MouseEnter="btnInventory1_MouseEnter" MouseLeave="MouseLeaveAnyObject" Margin="270,137,0,0" Click="btnSave2_Click"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> <Button x:Name="btnSaveEmpty3" Panel.ZIndex="100" HorizontalAlignment="Left" Height="93" VerticalAlignment="Top" Width="166" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" MouseEnter="btnInventory1_MouseEnter" MouseLeave="MouseLeaveAnyObject" Margin="480,139,0,0" Click="btnSave3_Click"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> <Button x:Name="btnSaveEmpty4" Panel.ZIndex="100" HorizontalAlignment="Left" Height="93" VerticalAlignment="Top" Width="164" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" MouseEnter="btnInventory1_MouseEnter" MouseLeave="MouseLeaveAnyObject" Margin="700,133,0,0" Click="btnSave4_Click"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> <Button x:Name="btnSaveEmpty5" Panel.ZIndex="100" HorizontalAlignment="Left" Height="93" VerticalAlignment="Top" Width="164" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" MouseEnter="btnInventory1_MouseEnter" MouseLeave="MouseLeaveAnyObject" Margin="917,139,0,0" Click="btnSaveEmpty5_Click"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> <Image x:Name="imgSave1" HorizontalAlignment="Left" Height="101" Margin="43,143,0,0" VerticalAlignment="Top" Width="172" Source="Resources/Images/Interface/default.bmp" Stretch="Fill"/> <Image x:Name="imgSave2" HorizontalAlignment="Left" Height="101" Margin="263,131,0,0" VerticalAlignment="Top" Width="172" Source="Resources/Images/Interface/default.bmp" Stretch="Fill"/> <Image x:Name="imgSave3" HorizontalAlignment="Left" Height="101" Margin="478,131,0,0" VerticalAlignment="Top" Width="172" Source="Resources/Images/Interface/default.bmp" Stretch="Fill"/> <Image x:Name="imgSave4" HorizontalAlignment="Left" Height="101" Margin="693,131,0,0" VerticalAlignment="Top" Width="173" Source="Resources/Images/Interface/default.bmp" Stretch="Fill"/> <Image x:Name="imgSave5" HorizontalAlignment="Left" Height="101" Margin="913,131,0,0" VerticalAlignment="Top" Width="173" Source="Resources/Images/Interface/default.bmp" Stretch="Fill"/> <Button x:Name="btnSaveCancel" Panel.ZIndex="100" HorizontalAlignment="Left" Height="86" VerticalAlignment="Top" Width="162" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" MouseEnter="btnInventory1_MouseEnter" MouseLeave="MouseLeaveAnyObject" Margin="1131,139,0,0" Click="btnSaveCancel_Click"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> </Grid> <Image x:Name="imgResume" HorizontalAlignment="Left" Height="215" Margin="469,105,0,0" VerticalAlignment="Top" Width="383" Source="Resources/Images/Interface/Main Menu/Menu_resume_g.png"/> <Image x:Name="imgSave" HorizontalAlignment="Left" Height="215" Margin="469,205,0,0" VerticalAlignment="Top" Width="383" Source="Resources/Images/Interface/Main Menu/Menu_save_g.png"/> <Image x:Name="imgLoad" HorizontalAlignment="Left" Height="215" Margin="469,306,0,0" VerticalAlignment="Top" Width="383" Source="Resources/Images/Interface/Main Menu/Menu_load_g.png"/> <Image x:Name="imgOptions" HorizontalAlignment="Left" Height="215" Margin="469,406,0,0" VerticalAlignment="Top" Width="383" Source="Resources/Images/Interface/Main Menu/Menu_options.png"/> <Image x:Name="imgCredits" HorizontalAlignment="Left" Height="215" Margin="469,506,0,0" VerticalAlignment="Top" Width="383" Source="Resources/Images/Interface/Main Menu/Menu_credits.png"/> <Image x:Name="imgQuit" HorizontalAlignment="Left" Height="215" Margin="469,587,0,-11" VerticalAlignment="Top" Width="383" Source="Resources/Images/Interface/Main Menu/Menu_quit.png" Grid.RowSpan="2"/> <Button x:Name="btnResume_Game" Panel.ZIndex="100" HorizontalAlignment="Left" Height="72" Margin="534,180,0,0" VerticalAlignment="Top" Width="253" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" Click="btnResume_Game_Click"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> <Button x:Name="btnSave_Game" Panel.ZIndex="100" HorizontalAlignment="Left" Height="72" Margin="534,280,0,0" VerticalAlignment="Top" Width="253" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" Click="btnSave_Game_Click"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> <Button x:Name="btnLoad_Game" Panel.ZIndex="100" HorizontalAlignment="Left" Height="72" Margin="534,379,0,0" VerticalAlignment="Top" Width="253" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" Click="btnLoad_Game_Click"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> <Button x:Name="btnOptions" Panel.ZIndex="100" HorizontalAlignment="Left" Height="72" Margin="534,479,0,0" VerticalAlignment="Top" Width="253" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" Click="btnOptions_Click"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> <Button x:Name="btnCredits" Panel.ZIndex="100" HorizontalAlignment="Left" Height="72" Margin="534,581,0,0" VerticalAlignment="Top" Width="253" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" Click="btnCredits_Click"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> <Button x:Name="btnQuit" Panel.ZIndex="100" HorizontalAlignment="Left" Height="72" Margin="534,679,0,0" VerticalAlignment="Top" Width="253" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" Click="btnQuit_Click"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> <MediaElement x:Name="musTheme3" Panel.ZIndex="1001" HorizontalAlignment="Left" Height="47" Margin="1290,21,0,0" VerticalAlignment="Top" Width="50" Source="Resources/Music/theme_3.wav" LoadedBehavior="Manual" RenderTransformOrigin="3.464,0.571" MediaOpened="AnySoundStart" MediaEnded="musTheme3_MediaEnded"/> <Image x:Name="imgNew" HorizontalAlignment="Left" Height="215" Margin="469,105,0,0" VerticalAlignment="Top" Width="383" Source="Resources/Images/Interface/Main Menu/Menu_new_g.png" d:IsHidden="True"/> <Button x:Name="btnNew_Game" Panel.ZIndex="200" HorizontalAlignment="Left" Height="72" Margin="534,180,0,0" VerticalAlignment="Top" Width="253" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" Click="btnNew_Game_Click_1"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> <Image x:Name="imgNew_Pressed" HorizontalAlignment="Left" Height="215" Margin="469,107,0,0" VerticalAlignment="Top" Width="383" Source="Resources/Images/Interface/Main Menu/Menu_new_g.png" d:IsHidden="True" Visibility="Hidden"/> <Grid x:Name="areaGameSaved" Panel.ZIndex="1011" HorizontalAlignment="Left" Height="245" Margin="11,-839,0,0" VerticalAlignment="Top" Width="1340" IsVisibleChanged="areaLoad_IsVisibleChanged"> <Grid.Background> <ImageBrush ImageSource="Resources/Images/Interface/Main Menu/img_GAME_SAVED.jpg" Stretch="Uniform"/> </Grid.Background> <Image x:Name="imgBackSaved" HorizontalAlignment="Left" Height="215" Margin="478,76,0,-53" VerticalAlignment="Top" Width="383" Source="Resources/Images/Interface/Main Menu/img_back.png"/> <Button x:Name="btnBackSaved" Panel.ZIndex="100" HorizontalAlignment="Left" Height="58" VerticalAlignment="Top" Width="253" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" MouseEnter="btnInventory1_MouseEnter" MouseLeave="MouseLeaveAnyObject" Margin="547,149,0,0" Click="btnBackSaved_Click"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> </Grid> <Grid x:Name="areaNotAvailable" Panel.ZIndex="1011" HorizontalAlignment="Left" Height="245" Margin="11,-1114,0,0" VerticalAlignment="Top" Width="1340" IsVisibleChanged="areaLoad_IsVisibleChanged"> <Grid.Background> <ImageBrush ImageSource="Resources/Images/Interface/Main Menu/img_NOT_AVAILABLE_YET.jpg" Stretch="Uniform"/> </Grid.Background> <Image x:Name="imgBackNotAvailable" HorizontalAlignment="Left" Height="215" Margin="478,76,0,-53" VerticalAlignment="Top" Width="383" Source="Resources/Images/Interface/Main Menu/img_back.png"/> <Button x:Name="btnBackNotAvailable" Panel.ZIndex="100" HorizontalAlignment="Left" Height="58" VerticalAlignment="Top" Width="253" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" MouseEnter="btnInventory1_MouseEnter" MouseLeave="MouseLeaveAnyObject" Margin="547,149,0,0" Click="btnBackNotAvailable_Click"> <Button.Template> <ControlTemplate> <Image Source="Resources/Images/Interface/Blank.png" Stretch="Fill" Margin="12,0,6,0"/> </ControlTemplate> </Button.Template> </Button> </Grid> <Label Content="0.7.1" HorizontalAlignment="Left" Height="46" Margin="1258,724,0,0" VerticalAlignment="Top" Width="53" FontSize="24" Foreground="#FFFBEEEE"/> <Button x:Name="btnResolution" Content="Button" HorizontalAlignment="Left" Height="104" Margin="1040,644,0,0" VerticalAlignment="Top" Width="181" Click="btnResolution_Click"/> </Grid>Xaml at the start:<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Name="wdwMain" x:Class="RealityIncognita.MainWindow" Height="900" Width="1600" ResizeMode="NoResize" WindowState="Maximized" Cursor="Cross" WindowStyle="None" Loaded="wdwMain_Loaded"><Grid x:Name="areaContainer" HorizontalAlignment="Left" Height="900" VerticalAlignment="Top" Width="1600">How it looks now:How it should look:Thank you,Evgenie 解决方案 Just remove the HorizontalAlignment="Left" Height="600" VerticalAlignment="Top" Width="800" from your grid so that grid can stretch to the whole window,if you need these values use it on the window itselfEdit:Okay, I see that you're setting the height and width for each element(like the buttons) inside the grid , and you're setting the margin to move them to the correct place,This will not work with different resolutions. lets say you set the window width to 800 and your button is set to be 200. if you change the window width to 1024, this change will not be reflected automatically to the buttons, it will always be 200 (and same goes for the margin)The correct solution is to rewrite the xaml code in the correct way, (you will use Grids with Grid.ColumnsDefinition/RowDefinition, Stackpanels ..etc) without setting the values in pixels.But if you're in hurry you can put all elements in a Viewbox:<Window .... <Viewbox Stretch="Fill"> <Grid x:Name="areaContainer" .... </Grid> </Viewbox></Window>Now note that using viewbox will stretch your content based on the Viewbox's width and height (so its like what you did in the graphics editor).Also note that Viewbox should be avoided as it's very expensive in terms of resources 这篇关于需要具有较低分辨率的图像“拉伸”屏幕大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 13:36