How to remove padding from content dialog?

做~自己de王妃 提交于 2020-08-24 10:19:09

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/50665277/how-to-remove-padding-from-content-dialog

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!