gpt4 book ai didi

wpf - 不同大小的WPF表单-设计模式与运行时模式

转载 作者:行者123 更新时间:2023-12-04 22:35:39 30 4
gpt4 key购买 nike

对于初学者的问题,我感到很抱歉,但“在创建WPF表单时,我是一个新手。
我在Visual Studio中设置和查看表单的正确大小时遇到​​一些问题。
在设计模式下,其大小比在运行时模式下的大。
这里是XAML。有任何想法吗???

<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"
xmlns:local="clr-namespace:EnginedrawWPF"
xmlns:h="http://helix-toolkit.org/wpf" x:Class="MainWindow"
mc:Ignorable="d"
Title="Motore di disegno" Height="400.0" Width="970.0" ResizeMode="NoResize">
<Grid Margin="0,0,0,0">

<h:HelixViewport3D x:Name="helixviewport3dobj" Height="301" Margin="207,10,10.2,0" h:VerticalAlignment="Top" Foreground="Black" Background="#FFC0E2B5" >

<h:HelixViewport3D.DefaultCamera>
<PerspectiveCamera Position="0,-3.5,3.5" LookDirection="0,3.5,-3.5" UpDirection="0,0,1" FieldOfView="61" NearPlaneDistance="0.001"/>
</h:HelixViewport3D.DefaultCamera>
<h:SunLight />
<h:GridLinesVisual3D Fill="#FFB9B9B9" Thickness="0.01" MinorDistance="0.2" MajorDistance="1"/>
</h:HelixViewport3D>
<Button x:Name="CBlineare" Content="Nuovo tratto lineare" HorizontalAlignment="Left" Height="30" Margin="10,10,0,0" VerticalAlignment="Top" Width="181"/>
<Button x:Name="CBcurva90" Content="Aggiungi curva 90°" HorizontalAlignment="Left" Height="30" Margin="10,57,0,0" VerticalAlignment="Top" Width="181"/>
<Button x:Name="CBcurva45" Content="Aggiungi curva 45°" HorizontalAlignment="Left" Height="30" Margin="10,105,0,0" VerticalAlignment="Top" Width="181"/>
</Grid>
</Window>

screenshot

最佳答案

您可以将Grid标签放在原始Grid标签内,并手动设置Height和Width以适合设计尺寸。
然后,将SizeToContent="WidthAndHeight"放入Window标记。

MainWindow.xaml的示例(Visual Studio 2017社区+ WPF):

<Window x:Class="_171207_t0936_controlLocation.MainWindow"
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"
xmlns:local="clr-namespace:_171207_t0936_controlLocation"
mc:Ignorable="d"
Title="MainWindow" Height="378.431" Width="607.353"
SizeToContent="WidthAndHeight">
<Grid>
<!-- In order to avoid the difference in size of debug and run modes -->
<!-- set "SizeToContent=WidthAndHeight" -->
<!-- Then put Grid insdie the original Grid with Height and Width set manually -->
<!-- to fit into the design size -->
<Grid>
<Button Content="Button" HorizontalAlignment="Left"
Margin="430,10,0,0" VerticalAlignment="Top" Width="75"/>
</Grid>
</Grid>
</Window>

关于wpf - 不同大小的WPF表单-设计模式与运行时模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34718588/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com