Static Members Not Supported ?
Hi,
I'm trying to bind a field to a constant in code.
Here is my xaml:
And my C# code looks like this:
When I do this, I'm getting an error at runtime:
I'm confused about the error - is it saying the 'x:Static' part in my xaml is not allowed? Or is the problem that my class is static? The variable is a constant so I'm not sure if it's a mis-detection on that?
thanks,
sam
I'm trying to bind a field to a constant in code.
Here is my xaml:
Code: Select all
<MyUserControl MyBindingId="{x:Static local:Action.Id}">
Code: Select all
namespace Foo.Bar
{
public static class Action
{
public const int Id = 42;
}
}
Code: Select all
Static members not supported. Can't use 'Foo.Bar.Action.Interact'
thanks,
sam
-
sfernandez
Site Admin
- Posts: 3154
- Joined:
Re: Static Members Not Supported ?
Hi Sam,
It means that current x:Static implementation does not support accessing static members in classes (see here), it only works with enum values and a few more scenarios described in the documentation.
Perhaps you can use the DP default value option in this case, could that work for you?
It means that current x:Static implementation does not support accessing static members in classes (see here), it only works with enum values and a few more scenarios described in the documentation.
Perhaps you can use the DP default value option in this case, could that work for you?
Re: Static Members Not Supported ?
Hmmm - My use case is that I'm trying to use code generated by Rewired (we are using it for input) to bind controls to specific actions in order to create a user interface so users can rebind controls. The code that Rewired generates uses constants rather than an enum value. I'll see if I can do something else on my end.
thanks,
sam
thanks,
sam
-
sfernandez
Site Admin
- Posts: 3154
- Joined:
Re: Static Members Not Supported ?
I was referring to this case, I think it would work the same for const values.
Code: Select all
public class SizeHelper : DependencyObject
{
public static float BorderWidth { get { return 16.0f } };
#if NOESIS
public static readonly DependencyProperty BorderWidthProperty = DependencyProperty.Register(
"BorderWidth", typeof(float), typeof(SizeHelper),
new PropertyMetadata(SizeHelper.BorderWidth));
#endif
}
Who is online
Users browsing this forum: No registered users and 4 guests