如何删除 ContentDialog 中的填充/边距? This或其他没有帮助我。我尝试在 ContentDialog 的标签和根网格中使用填充和边距,如下所示。
<ContentDialog... Padding="0" Margin="0">
<Grid Background="Bisque" Width="500" Height="400" Padding="0" Margin="0">
<Button Content="X" Height="40" Width="40" VerticalAlignment="Top"
HorizontalAlignment="Right"></Button>
</Grid>
没有运气。但是,在 Live Visual Tree 中,我发现一个 Grid(DialogSpace) 占据了这个区域。但是如何访问和修改它呢?
最佳答案
在这些情况下,第一步应该始终是寻找 generic.xaml 文件,该文件负责定义多个控件的模板。
查看为 10.0.16299 构建定义的文件( Fall Creators Update ),我可以找到以下定义的资源:
<Thickness x:Key="ContentDialogPadding">24,18,24,24</Thickness>
后来在
Grid
上被引用,在 ContentDialog
的定义过程中命名为 DialogSpace(正如您正确识别的那样)的模板。<Grid x:Name="DialogSpace" Padding="{ThemeResource ContentDialogPadding}">
Thickness
项目中具有相同 key 标识符的资源 ,在那里您将值 24,18,24,24 覆盖为
更符合你的意图。
通过在 App.xaml 上实现,您可以在范围是整个应用程序的位置覆盖此资源。但是想象一下您的应用程序只有一个
ContentDialog
或者你只想在一个地方做这件事,在一个较低范围的地方定义它是非常有意义的,比如在 ContentDialog
资源级别,如下所示:<ContentDialog ...>
<ContentDialog.Resources>
<Thickness x:Key="ContentDialogPadding">0,0,0,0</Thickness>
</ContentDialog.Resources>
....
</ContentDialog>
Padding
简单地删除对 ContentDialogPadding 资源的引用。 DialogScope 网格的依赖属性。但是这些模板显然真的很大,而且对于这么小的修改,似乎不是合适的选择。
generic.xaml 文件的位置如下:
C:\Program Files (x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\{build version}\Generic
关于uwp - 如何从内容对话框中删除填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50665277/