How do I assign a decimal property from Xaml? #9441
Unanswered
danielgruethling
asked this question in
Q&A
Replies: 2 comments 2 replies
-
An xaml file is just a text file. Even if it did support Decimals that just means that it would convert the text to a decimal for you automatically. You can do that your self in code behind: private Decimal _value;
public string Value
{
set
{
_value = Convert.ToDecimal(value);
}
} (error checking omitted) |
Beta Was this translation helpful? Give feedback.
1 reply
-
I have tried a workaround from ChatGPT to create a converter and use
but that does not work either. Now just states: Failed to assign to property 'Namespace.Signal.Value'. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a class Signal with the following property:
I now want to assign a value to that property but this does not seem to work.
I create some complex object using
which contains multiple of the Signal objects.
But when the compiler tries to create a Signal object I get a:
I need the property to be of type decimal and I can not assign the values after creating the objects. They have to be assigned during the XamlReader.Load([...]).
Is there some workaround I can use? I tried creating a resource with x:Decimal and using StaticResource to assign that but x:Decimal is not supported by the ancient Xaml schema WinUI3 still uses. Changing the text to "5.0" or "5,0" does not work either.
Beta Was this translation helpful? Give feedback.
All reactions