Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove padding from content dialog?

Tags:

uwp

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?

enter image description here

like image 752
Mg Bhadurudeen Avatar asked Jun 03 '18 10:06

Mg Bhadurudeen


1 Answers

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
like image 58
André B Avatar answered Sep 16 '22 13:09

André B