Silverlight 4 Equivalent to WPF "x:static"
Unfortunately, you can't directly use the DynamicResource and Static keywords in a Silverlight's subset of XAML, but you can mimic their behavior. Here is the article on the topic:
In general, there is no easy way to migrate a project from WPF to Silverlight. They have very much in common, but strictly speaking are a different technologies.
Another way to achieve binding to static properties - to bind in code. Below is an example.
Main application class:
public partial class App : Application{ public static MyViewModel MyViewModel { get; private set; } // ...}
Main window markup:
<TextBlock Loaded="MyTextBlockLoaded" />
Main window back-code:
public partial class MainPage : PhoneApplicationPage{ // ... private void MyTextBlockLoaded(object sender, RoutedEventArgs e) { TextBlock textBlock = ((TextBlock)sender); if (textBlock.Tag == null) { textBlock.Tag = true; Binding bind = new Binding("MyInfo"); bind.Source = App.MyViewModel; bind.Mode = BindingMode.OneWay; textBlock.SetBinding(TextBlock.TextProperty, bind); } }}
Maybe the TextBlock.Tag
approach of checking, was Binding already set or not, isn't the most elegant one, but it works.