Page 1 of 1

Static members not supported

Posted: 19 Nov 2018, 15:49
by KeldorKatarn
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.
                        <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>

Re: Static members not supported

Posted: 22 Nov 2018, 18:11
by sfernandez
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:
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; }
  }
}
<TextBlock Margin="0,32,0,27">
  <Run Text="{x:Static properties:ApplicationStrings.Copyright}" />
  <LineBreak />
  <Run Text="{x:Static properties:Strings.RightsReserved}" />
</TextBlock>
This is something we want to correctly document for the next version because it is not clear.

Re: Static members not supported

Posted: 04 Oct 2019, 13:37
by stonstad
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?

Re: Static members not supported

Posted: 04 Oct 2019, 17:03
by sfernandez
It should be supported, in fact we use it in some of our samples, for example in TicTacToe:
namespace TicTacToe
{
    public enum State
    {
        Player1 = 1,
        Player2 = 2,
        Tie,
        WinRow0,
        ...
    }
}
<UserControl x:Class="TicTacToe.MainWindow"
        ...
        xmlns:local="clr-namespace:TicTacToe">
        
        ...
        <DataTrigger Binding="{Binding State}" Value="{x:Static local:State.Player1}">
Could you please share your enum definition (including the namespace), and how in xaml are you using it?