所以我有一个 ViewBox
可以在调整窗口大小时缩放 Grid
但是当显示窗口时它已最大化到我的屏幕高度,宽度也比它应该的要大.使用 Width="301" Height="287"
将窗口设置为 301*87,但由于某种原因被忽略。设置 ViewBox
的宽度/高度会更正起始窗口大小,但会阻止它在调整大小时缩放 Grid
的内容。如何让 ShowDialog()
上的窗口大小从 301*287 开始,同时保持 ViewBox
正常工作?
<Window x:Class="Test.Dialogs.DatatypesDialog"
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:Test.Dialogs"
mc:Ignorable="d"
Title="DatatypesDialog" Width="301" Height="287" Background="Black" SizeToContent="WidthAndHeight" MinWidth="301" MinHeight="287" WindowStartupLocation="CenterOwner">
<Viewbox >
<Grid Width="285" Height="248" >
<ListBox x:Name="lbDTypes" Margin="10,10,0,0" SelectionMode="Single" HorizontalAlignment="Left" Width="140" Height="228" VerticalAlignment="Top"/>
<TextBox x:Name="tbType" Margin="155,10,0,0" TextWrapping="Wrap" Text="" HorizontalAlignment="Left" Width="120" Height="23" VerticalAlignment="Top"/>
<Button Content="New" Click="NewDType" Margin="155,38,0,0" Height="20" VerticalAlignment="Top" HorizontalAlignment="Left" Width="120"/>
<Button Content="Move Up" HorizontalAlignment="Left" Margin="155,128,0,0" VerticalAlignment="Top" Width="120"/>
<Button Content="Move Down" HorizontalAlignment="Left" Margin="155,153,0,0" VerticalAlignment="Top" Width="120"/>
<Button Content="Remove" HorizontalAlignment="Left" Margin="155,88,0,0" VerticalAlignment="Top" Width="120"/>
<Button Content="Modify" Margin="155,63,0,0" Height="20" VerticalAlignment="Top" HorizontalAlignment="Left" Width="120"/>
<Separator HorizontalAlignment="Left" Height="20" Margin="155,108,0,0" VerticalAlignment="Top" Width="120"/>
<Separator HorizontalAlignment="Left" Height="20" Margin="155,173,0,0" VerticalAlignment="Top" Width="120"/>
<Button Content="Save" HorizontalAlignment="Left" Margin="155,193,0,0" VerticalAlignment="Top" Width="120" RenderTransformOrigin="0.583,-0.025"/>
<Button Content="Close" HorizontalAlignment="Left" Margin="155,218,0,0" VerticalAlignment="Top" Width="120"/>
</Grid>
</Viewbox>
</Window>