Reputation: 6070
I want to declare a variable for Margin value like this:
<x:MarginStruct x:Key="myMargin1">10,5,20,20</x:MarginStruct>
then I could reuse this resource value for some UI elements like this:
<TextBlock Margin={StaticResource myMargin1}">text1</TextBlock>
<TextBlock Margin={StaticResource myMargin1}">text2</TextBlock>
Should I define a class/struct MarginStruct with four double members?
If that is a way, what if margin value likes "10,5" or "10" in some situations, how should we handle it?
Thanks! Any ideas is appreciated!
Upvotes: 0
Views: 996
Reputation: 38336
You can declare this resource:
<Thickness x:Key="MyMargin" Left="10" Top="5" Right="20" Bottom="20" />
and then use this:
<TextBlock Margin="{StaticResource MyMargin}">text1</TextBlock>
Upvotes: 5
Reputation: 13
Visual Studio can create this variable for you.
In the text block properties window click little square next to the padding boxes and then click "convert to new resource".
[
Upvotes: 1