【发布时间】:2021-01-14 20:30:37
【问题描述】:
我目前正在制作一个应该在整个程序窗口上显示Image 的软件。 Buttons 应该浮在上面以控制软件。
浮动的Button 与ZIndex 配合得很好,但问题是它要么卡在左上角,要么卡在静态位置。
想法是被卡在正确的程序边界上。调整程序大小后,它仍应保持在右边框上。 我试过水平对齐,但完全没有效果。
这是目前的 xaml:
<Window x:Class="TarkovMapper_2._0.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:TarkovMapper_2._0"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid HorizontalAlignment="Stretch" Width="Auto" Height="Auto" VerticalAlignment="Stretch">
<Image Grid.ZIndex="1" x:Name="Map_Image" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<DockPanel Grid.ZIndex="2" Width="Auto" Height="Auto" HorizontalAlignment ="Right" VerticalAlignment="Top" >
<Button DockPanel.Dock="Right" Grid.ZIndex="2" x:Name="Edit_Button" Content="Button" HorizontalAlignment="Right" VerticalAlignment="Center" Width="50" Height="49"/>
</DockPanel>
</Grid>
</Window>
看来DockPanel 将是正确的方法,但DockPanel 本身在自动模式下调整为按钮的大小(然后它本身卡在顶部/左侧,或者我可以静态调整它的大小但它不会调整大小然后使用应用程序。
【问题讨论】:
标签: c# wpf button controls alignment