jpattersonCSpeed
Topic Author
Posts: 7
Joined: 10 Mar 2020, 21:27

Binding Multiple Values to a Margin

18 Mar 2020, 14:09

Hello again,

I am trying to apply a margin to an element that will eventually have bindings to make certain sides of the margin change based on calculations. In WPF, this is achieved through the following link under "XAML Property Element Usage":
https://docs.microsoft.com/en-us/dotnet ... ment-usage

A quick demo app in WPF with a TextBlock confirms that this works as described:
<TextBlock Text="Some Text">
  <TextBlock.Margin>
    <Thickness Left="100" Top="100" Bottom="0" Right="0"/>
  </TextBlock.Margin>
</TextBlock>
The same code inside of Noesis doesn't produce the same results, and running it in the XAMLtoy app produces errors stating "Can't assign property to abstract class 'Thickness'." Since this is different behavior from WPF is this considered a bug? If it is not a bug, is there a different workflow that produces the same results?
Thanks.
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: Binding Multiple Values to a Margin

18 Mar 2020, 17:31

In WPF you can specify a Thickness value using their individual properties (we don't support this in Noesis), but you won't be able to use bindings to set those properties:
<TextBlock Text="Some Text">
  <TextBlock.Margin>
    <Thickness Left="{Binding LeftMargin}" Top="100" Bottom="0" Right="0"/>
  </TextBlock.Margin>
</TextBlock>
This will throw the error: "A 'Binding' cannot be set on the 'Left' property of type 'Thickness'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject".

Struct properties should be set as a whole object via bindings:
<TextBlock Text="Some Text" Margin="{Binding TextMargin}"/>
 
jpattersonCSpeed
Topic Author
Posts: 7
Joined: 10 Mar 2020, 21:27

Re: Binding Multiple Values to a Margin

18 Mar 2020, 21:46

Ah I would have thought that the binding would have worked. No worries, this is a hint that I have to change up the area of the UI that was going to use this to be something better. Thanks.

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], jsantos, Semrush [Bot] and 10 guests