MarcusM-PDX
Topic Author
Posts: 4
Joined: 31 May 2023, 10:24

WPF cannot get the length from a String, because it's actually Boxed<String>

31 May 2023, 10:45

Error Message
[Noesis - Binding]: Can't solve PropertyPath: Type 'Boxed<String>' does not contain a property named 'Length'
[Noesis - Binding]: Binding failed: Path=CustomText.Length, Source=Game.TechnologyWrapper(''), Target=Button('Slot'), TargetProperty=Game.Custom.Int

Code
game:Custom.Int="{Binding CustomText.Length}"

Explanation
The situation is that as part of a Style (for a button) I'm trying to get the length of the CustomText Noesis::String. The binding for CustomText is working, as it's content is successfully displayed within the Style, and I'm attempting to make a convenient way to collapse the textbox if the content of CustomText is "". My approaches all seemed like they should work, but weren't and after drilling down and simplifying it, I realized that the point at which I'm binding the string is revealing the shown error, that the String is actually secretly a Boxed<String>.

Have I set something up wrong somewhere, or am I missing something?

Thanks!
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: WPF cannot get the length from a String, because it's actually Boxed<String>

31 May 2023, 18:23

Hi Marcus,

We have to improve the binding error message, because a Boxed<String> is handled in fact as a simple String by the binding system, so we should just show 'String' in that message. Anyway, the problem that is described in that binding error is not related to that. What happens is that Noesis String does not expose a Length property that can be bound like it happens in WPF/C#.

To solve this you can use a Converter that takes the string and returns its length:
game:Custom.Int="{Binding CustomText, Converter={StaticResource StringToLengthConverter}}"
Could you try that?
 
MarcusM-PDX
Topic Author
Posts: 4
Joined: 31 May 2023, 10:24

Re: WPF cannot get the length from a String, because it's actually Boxed<String>

13 Jun 2023, 09:38

Using a converter to get the Length worked perfectly, even gave myself a few other features in the process.

Thanks!

Who is online

Users browsing this forum: No registered users and 87 guests