How to replace x:Static in Metro Apps? RRS feed

  • Question

  • I’m attempting to port some code over from a WPF application to a Metro version. In a few places, I attempt to access a value that is defined as an application constant, but the code I was using to retrieve it uses the “x:Static” syntax, which is no longer supported. Visual Studio says "The type x:Static was not found."

        <RowDefinitionHeight="{Binding Source={x:Static local:AppConstants.HEIGHT_CONSTANT}}"/>

    What is the right way to get access to application constants from XAML markup for Windows 8 Metro?

    Thanks in advance.

    Monday, January 30, 2012 8:46 PM


All replies

  • Does StaticResource work for you?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    Tuesday, January 31, 2012 4:25 PM
  • x:Static allows access to a static member on a type (vs. an instance member), while StaticResource allows access to a resource (like a Brush, etc.) defined elsewhere in XAML.  They are very different things even though both have "Static" in the name.
    actiprosoftware.com - Professional WPF, Silverlight, and WinForms UI controls and components
    Tuesday, January 31, 2012 4:34 PM
  • Yes, StaticResource works, but like Bill said, I can only use it to access XAML resources.
    Tuesday, January 31, 2012 4:59 PM
  • I would plug in a converter, to transform a string into the appropriate constant value. I did something similar -but for enumerations instead of constants- here: http://blogs.u2u.be/diederik/post/2011/12/27/Databinding-to-an-enumeration-in-WinRT.aspx
    Wednesday, February 1, 2012 9:58 PM
  • Thank you, Diederik - I'll try that.
    Thursday, February 2, 2012 2:00 PM
  • I noticed x:Static still isn't in the community preview.

    Yes there are workarounds for this, but including x:Static (and x:Type for that matter) are simple things that make developers' lives much easier.  They aren't hard for you guys to build into the platform (copy the code from WPF), and I really think they should make the cut for the WinRT RTM.  We use them numerous places throughout our WPF code.

    actiprosoftware.com - Professional WPF, Silverlight, and WinForms UI controls and components

    Monday, March 5, 2012 6:43 PM
  • Hi Bill,
    They should include that , else it makes it so tough!!.
    @matt , please do give the feed back .
    Sunday, October 28, 2012 2:52 PM
  • I don't get it. Come on, Microsoft. Why did you not include many features that were present in WPF into the Windows Store framework as well? Developing for the Windows Store would be so much easier if you did. I have been having quite a hellish experience trying to get by after I have been using WPF. I bet that if I want to emulate advanced features available in WPF, I need to learn C++, right? Of course. No learning curve there or anything.

    No wonder only 1/3 of developers are considering developing for Metro.

    At lease you brought back RenderTargetBitmap.

    Sunday, November 3, 2013 12:18 AM
  • Does anyone know if this very basic and fundamental feature (that existed in WPF and Silverlight5 -- over 4 years ago) is in Windows 10? :P
    • Edited by Mike-EEE Sunday, March 29, 2015 11:16 PM
    Sunday, March 29, 2015 11:16 PM