我正在尝试为飞行模拟器创建一个应用程序 用户可以预设窗口位置和大小的飞机 第一个屏幕截图中显示的一组弹出式广播显示。
但是,我遇到了一些问题。在第二 截图,当我水平缩放主网格时 使用网格分割器时,图像也会垂直增大 水平而不是保持在初始高度。任何 想法如何解决这个问题?
答案 0 :(得分:0)
好的解决方案是使用网格并设置Grid.Row图像被分配给。然后通过缩放网格我可以获得所需的效果。
XAML:
<Grid x:Name="spGrid" Height="154" Width="101" Margin="0,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" MouseDown="PosStart" MouseMove="PosDelta" MouseUp="PosEnd">
<Grid.RowDefinitions>
<RowDefinition x:Name="spRow1" Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="spCol1" Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<GridSplitter Grid.Column="1" Grid.RowSpan="5" Width="1" HorizontalAlignment="Right" VerticalAlignment="Stretch" DragDelta="PanelXDelta" DragStarted="PanelXStart"/>
<GridSplitter Grid.Row="1" Grid.ColumnSpan="4" Height="1" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" DragDelta="PanelYDelta" DragStarted="PanelYStart"/>
<Grid Grid.Column="0" Grid.Row="0" x:Name="spStack" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Image Grid.Row="0" x:Name="imgKMA30" Source="UI/KMA30.jpg" StretchDirection="Both" Stretch="Fill" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
<Image Grid.Row="1" x:Name="imgKR165A" Source="UI/KX165A.jpg" StretchDirection="Both" Stretch="Fill" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
<Image Grid.Row="2" x:Name="imgKX165" Source="UI/KX165.jpg" StretchDirection="Both" Stretch="Fill" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
<Image Grid.Row="3" x:Name="imgKN62A" Source="UI/KN62A.jpg" StretchDirection="Both" Stretch="Fill" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
<Image Grid.Row="4" x:Name="imgKR87" Source="UI/KR87.jpg" StretchDirection="Both" Stretch="Fill" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
<Image Grid.Row="5" x:Name="imgKT74" Source="UI/KT74.jpg" StretchDirection="Both" Stretch="Fill" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
</Grid>
</Grid>
C#:
private void PanelXDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
spGrid.Width += e.HorizontalChange;
}
private void PanelYDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
spGrid.Height += e.VerticalChange;
}