I'm writing a Phone 7 app and I would like to reference constant values in markup. I believe the way one is supposed to do this is via x:Static.
However, Visual Studio keeps claiming it has no knowledge of x:static
. What is the secret sauce here? I have the following:
<phone:PhoneApplicationPage
...
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
...
<Image Height="{x:Static App.ImageHeight}" ... />
...
And of course:
public partial class App : Application
{
public const double ImageHeight = 100;
...
The error message is "The type 'x:Static' was not found. Verify that...".
You must use a browser that supports Silverlight content to access a Silverlight page. To work around this issue on versions 42 to 44 of Chrome, follow these steps: On the address bar in Chrome, type chrome://flags/#enable-npapi . In the Enable NPAPI Mac, Windows box, click Enable.
Using Silverlight outside the browser is as easy as bookmarking Web pages. Silverlight applications with out-of-browser support are simple to install, run, and uninstall. To install, just right-click the Web-based application and select install. The installer adds a shortcut to your desktop or Start menu.
x:Static
is only available in WPF - neither Silverlight for the browser nor Silverlight for Windows Phone 7 support this markup extension.
The usual workaround is to create a (non-static) class that has properties which simply wrap the static properties you want, and create an instance of that as a Resource and bind against it that way.
Example*:
public class StaticSideEnums
{
public static Side Bid { get { return Side.Bid; } }
public static Side Ask { get { return Side.Ask; } }
}
In the resources (app.xaml):
<ResourceDictionary>
<local:StaticSideEnums x:Key="StaticSideEnums"/>
</ResourceDictionary>
In the xaml where it's used:
<toolkit:ListPicker Name="picker" SelectionChanged="OnSelectionChanged">
<toolkit:ListPickerItem Content="Buy" Tag="{Binding Bid, Source={StaticResource StaticSideEnums}}" />
<toolkit:ListPickerItem Content="Sell" Tag="{Binding Ask, Source={StaticResource StaticSideEnums}}" />
</toolkit:ListPicker>
*This example is taken from an answer in Using localized strings in a ListPicker populated from Enum
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With