- KeldorKatarn
- Posts: 193
- Joined:
Static members not supported
When I'm trying to access a string resource directly in XAML, I'm getting this error:
NoesisException: Assets/NoesisGUI/HelloWorld/Views/XYZ.xaml(61): Static members not supported.
NoesisException: Assets/NoesisGUI/HelloWorld/Views/XYZ.xaml(61): Static members not supported.
Code: Select all
<TextBlock
Margin="0,32,0,27">
<!-- Style="{StaticResource TextBlock.Standard}"> -->
<Run
Text="{x:Static properties:Strings.Copyright}" />
<LineBreak />
<Run
Text="{x:Static properties:Strings.RightsReserved}" />
</TextBlock>
-
sfernandez
Site Admin
- Posts: 3154
- Joined:
Re: Static members not supported
Type static members are not supported in Noesis: https://www.noesisengine.com/bugs/view.php?id=1305
Currently x:Static extension only works for enum values.
And we also support x:Static as a way to access the default value of a DependencyProperty. This isn't something available in WPF, but can be useful sometimes:
This is something we want to correctly document for the next version because it is not clear.
Currently x:Static extension only works for enum values.
And we also support x:Static as a way to access the default value of a DependencyProperty. This isn't something available in WPF, but can be useful sometimes:
Code: Select all
class ApplicationStrings : DependencyObject
{
public static readonly DependencyProperty CopyrightProperty = DependencyProperty.Register(
"Copyright", typeof(string), typeof(ApplicationStrings), new PropertyMetadata("(C) 2018 MyCompany"));
// the following accessor is required so the same code works in Blend
public static string Copyright
{
get { return CopyrightProperty.Metadata.DefaultValue; }
}
}
Code: Select all
<TextBlock Margin="0,32,0,27">
<Run Text="{x:Static properties:ApplicationStrings.Copyright}" />
<LineBreak />
<Run Text="{x:Static properties:Strings.RightsReserved}" />
</TextBlock>
Re: Static members not supported
Hello! I am trying this with an Enum and I'm seeing the not supported error. My syntax is:
<SomeElement Tag="{x:Static local:MyEnumType.MyEnumValue}"/>
Is there something I should include or am I maybe not doing this correctly?
<SomeElement Tag="{x:Static local:MyEnumType.MyEnumValue}"/>
Is there something I should include or am I maybe not doing this correctly?
-
sfernandez
Site Admin
- Posts: 3154
- Joined:
Re: Static members not supported
It should be supported, in fact we use it in some of our samples, for example in TicTacToe:
Could you please share your enum definition (including the namespace), and how in xaml are you using it?
Code: Select all
namespace TicTacToe
{
public enum State
{
Player1 = 1,
Player2 = 2,
Tie,
WinRow0,
...
}
}
Code: Select all
<UserControl x:Class="TicTacToe.MainWindow"
...
xmlns:local="clr-namespace:TicTacToe">
...
<DataTrigger Binding="{Binding State}" Value="{x:Static local:State.Player1}">
Who is online
Users browsing this forum: No registered users and 0 guests