I have a Grid control that I’d like to set the margin properties of in XAML and have them be pulled from SystemInformation.CaptionHeight. I’ve figured out how to do it in C# but I’d like to do it in XAML.
I haven’t used resources to set things like this before but I’ve tried variations like
<Grid>
<Grid.Margin>
<Thickness Top="{StaticResource {x:Static Forms:SystemInformation.CaptionHeight}}" Left="5" Right="5" Bottom="5" />
</Grid.Margin>
</Grid>
and
<Grid>
<Grid.Margin>
<Thickness Top="{x:Static Forms:SystemInformation.CaptionHeight}" Left="5" Right="5" Bottom="5" />
</Grid.Margin>
</Grid>
but to no avail. How do I dynamically set attributes like this at runtime?
Using a Binding, but specify that the Source is static and point it to the location of your property
Also,
Thickness.Topis not a DependencyProperty, so you can not bind it. Your best alternative would be to bindGrid.Marginusing a Converter, which takes the double value and converts it to aThicknessproperty.