Reputation: 1434
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?
Upvotes: 6
Views: 2119
Reputation: 1709
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}">
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>
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
Upvotes: 14