wpf - 我们如何在父窗口的垂直上边缘显示 UWP 用户控件?
问题描述
在XAML
此Microsoft 教程中显示父窗口的顶部边缘与UWP user control
. 问题:我们如何使用户控件与父窗口的上边缘对齐?备注:下面VerticalAlignment="Top"
的StackPanel
没有帮助。这个问题与这篇文章类似,但在不同的背景下。
<UserControl
x:Class="ClassLibUWP_inside_WPF.MyUserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ClassLibUWP_inside_WPF"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:winui="using:Microsoft.UI.Xaml.Controls"
mc:Ignorable="d"
d:DesignWidth="400" Height="329">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="211*"/>
<ColumnDefinition Width="189*"/>
</Grid.ColumnDefinitions>
<StackPanel Background="LightCoral" Grid.ColumnSpan="2">
<TextBlock>This is a simple custom UWP control</TextBlock>
<Rectangle Fill="Blue" Height="93" Width="100"/>
<TextBlock Text="{x:Bind XamlIslandMessage}" FontSize="50"></TextBlock>
<winui:RatingControl Height="32" />
</StackPanel>
</Grid>
</UserControl>
当您运行上述教程中构建的应用程序时,您会看到显示上述 UWP 用户控件的以下屏幕:
相反,我想按如下方式显示它[注意窗口标题和红色堆栈面板之间没有间隙]:
解决方案
UserControl
具有小于窗口高度的固定高度,因此在窗口中垂直居中。设置应该VerticalAlignment="Top"
给WindowsXamlHost
你想要的。
推荐阅读
- xamarin - 使用自定义文本样式时 Xamarin 应用程序崩溃
- javascript - 使用 JavaScript 对象动态填充 HTML
- html - 无法让“位置:粘性”在我的导航栏上工作。任何帮助表示赞赏
- algorithm - 给定一个矩形的 4 个点(具有某种旋转),确定一个点是否在矩形内
- asp.net - ASP.NET CheckBox 总是返回 false 值
- css - 在引导程序 4 中更改刷新列表换行符的颜色
- javascript - 在反应中创建一个类函数
- algorithm - 找到具有 2 个条件的 NFA
- jquery - Jquery根据所选选项将属性添加到URL
- c++ - 从主函数中的源读取函数变量而不传递严格的值