I am NEW to WPF. I have the following XAML code:
</Window>
...
<Canvas>
<TextBlock Canvas.Left="300" Canvas.Top="300">WORD1</TextBlock>
<TextBlock Canvas.Left="350" Canvas.Top="300">WORD2</TextBlock>
<TextBlock Canvas.Left="400" Canvas.Top="300">WORD3</TextBlock>
</Canvas>
</Window>
I would like to define “300” as a resource (say “myTop”) and replace all Canvas.Top=”300″ with Canvas.Top=”myTop”.
How can I do this in WPF/XAML? I looked into StaticResources and DataTemplates, but could not figure out a simple way. Thanks.
First of all you have to add xmlns to the window
And then define resource like this
And then you can use it: