I have the following two buttons in XAML:
<Button Content="Previous" Margin="10,0,0,10"/> <Button Content="Next" Margin="0,0,10,10"/>
How can I define "10" to be a variable so I can change it in one place, something like this:
PSEUDO CODE:
<variable x:key="theMargin"/> <Button Content="Previous" Margin="{Variable theMargin},0,0,{Variable theMargin}"/> <Button Content="Next" Margin="0,0,{Variable theMargin},{Variable theMargin}"/>
Extensible Application Markup Language (XAML /ˈzæməl/ ( listen)) is a declarative XML-based language that Microsoft developed for initializing structured values and objects.
xaml. If the style is not found in the theme dictionary, it looks in Generic. xaml i.e for controls whose look doesn't depend on the theme. This only applies to any custom controls you have defined i.e. classes derived from Control, directly or indirectly.
Try this:
add to the head of the xamlfile
xmlns:System="clr-namespace:System;assembly=mscorlib"
Then Add this to the resource section:
<System:Double x:Key="theMargin">2.35</System:Double>
Lastly, use a thickness on the margin:
<Button Content="Next"> <Button.Margin> <Thickness Top="{StaticResource theMargin}" Left="0" Right="0" Bottom ="{StaticResource theMargin}" /> </Button.Margin> </Button>
A lot of system types can be defined this way: int, char, string, DateTime, etc
Note: You're right... Had to do some better testing.. changed to code so that it should work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With