I have a XAML, containing information like this:
... Margin="10,20,30,40" ...
I know that it is very easy to set the left margin in a binding, as such:
Margin="{Binding margin_value}"
... but this would not fill in the values "20, 30, 40".
Everywhere I search on the internet, I see the same answer:
You are looking for Top, Left, Bottom and Right. In order to fill those in, here's the C# code.
I'm not interested in C# code, I would like to set it in the XAML directly as a binding result, but everything I tried (Margin.X="{Binding ...}", Margin.Left="{Binding ...}", Left.Margin="{Binding ...}", ...) seem not to work, although I'm convinced it should be really easy.
Does anybody know how to do this?
Thanks in advance
You can specify as few or many of the four Thickness-Properties as you like, be it one, two, three or four out of
Left,Top,LeftorButtom.However ommitting one just will implicitly make it hold the value of 0.
So all you gain is not writing the 0.
WPF built-in converter for
Marginor other properties of typeThicknesstakes 1, 2 or 4 arguments but not 3.And when you specify one or two its just a shorthand and all four value(s) are applied anyways.
So if you don't want to specify one of them you can do it with a more verbose syntax that names the properties:
But as already stated this is just kind of a lengthy way for specifying this markup:
Moreover a thickness is just a plain struct, it has no dependency properties. So you can't bind to the named four dimension properties. Conclusion: Use the built-in type converter and specify all 4 values where the shorthands don't satisfy your demands.