KeldorKatarn
Topic Author
Posts: 193
Joined: 30 May 2014, 10:26

Static members not supported

19 Nov 2018, 15:49

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>
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Static members not supported

22 Nov 2018, 18:11

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.
 
User avatar
stonstad
Posts: 241
Joined: 06 Jun 2016, 18:14
Location: Lesser Magellanic Cloud
Contact:

Re: Static members not supported

04 Oct 2019, 13:37

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?
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Static members not supported

04 Oct 2019, 17:03

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?

Who is online

Users browsing this forum: camimamedov and 26 guests