如何从内容对话框中删除填充? [英] How to remove padding from content dialog?

查看:22
本文介绍了如何从内容对话框中删除填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何去除 ContentDialog 中的内边距/边距?

解决方案

在这些情况下,第一步应该始终是去寻找 generic.xaml 文件,该文件负责定义模板的几个控件.

查看为 10.0.16299 构建(秋季创作者更新)定义的文件,我可以找到定义的以下资源:

<Thickness x:Key="ContentDialogPadding">24,18,24,24</Thickness>

ContentDialog 的定义过程中,稍后会在名为 DialogSpace(如您已正确识别)的 Grid 上引用它'l 模板.

  • 解决这个问题最简单的方法,就是在你的项目中定义你自己的 Thickness 资源,使用相同的 Key 标识符,将值 24,18,24,24 覆盖为更符合您的意图.

通过在 App.xaml 上实现,您可以在范围是整个应用程序的地方覆盖此资源.但是想象一下你的应用程序只有一个 ContentDialog 或者你只想在一个地方做这件事,在一个较低范围的地方定义它是非常有意义的,比如在 ContentDialog 资源级别,像这样:

<ContentDialog.Resources><厚度 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

How to remove the padding/margin in ContentDialog? This or other did not help me. I tried with padding & margin in both ContentDialog's tag and Root Grid as below.

<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>

with no luck. But, In Live Visual Tree, I found a Grid(DialogSpace) occupying this area. But how to access and modify it?

解决方案

In these situations the first step should always be to go look for the generic.xaml file, which is responsible for defining the template of the several controls.

Taking a look onto the file defined for the 10.0.16299 build (Fall Creators Update), I could find the following resource defined:

<Thickness x:Key="ContentDialogPadding">24,18,24,24</Thickness>

Which is later being referenced on a Grid, named DialogSpace (as you have correctly identified), during the definition of the ContentDialog's template.

<Grid x:Name="DialogSpace" Padding="{ThemeResource ContentDialogPadding}">

  • The easiest option to fix this issue, is for you to define your own Thickness resource in your project with the same Key identifier, where you override the values, 24,18,24,24, to something that better fits your intentions.

You can override this resource in a place where the scope is the entire application, by implementing it on the App.xaml. But imagining that your application only has a single ContentDialog or you only desire to do this at one place, it would make perfect sense to define this at a lower scoped place, like at the ContentDialog resource level, like this:

<ContentDialog ...>
    <ContentDialog.Resources>
       <Thickness x:Key="ContentDialogPadding">0,0,0,0</Thickness>
    </ContentDialog.Resources>
     ....
</ContentDialog>

  • The second option would consist in "importing" the template into the project, and simply remove the reference to the ContentDialogPadding resource by the Padding dependency property of the DialogScope Grid. But these templates are obviously really big, and for such a small modification, it does not seem like the appropriate option.

The location of the generic.xaml file is the following:

C:\Program Files (x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\{build version}\Generic

这篇关于如何从内容对话框中删除填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆