views:

265

answers:

2

I have writen a small applet in Silverlight and, while it works fine on Windows, it seems that on OSX the data binding part of the application (all those NotifyPropertyChanged calls) do not work. Does anyone know why this is? I've tried under both Firefox and Safari with the latest 2.0 download installed.

+1  A: 

Did you try using remote sliverlight debugging to the mac? I'd expect getting the debugger setup and turning on 1st chance exceptions has a good shot at showing you the problem.

Steve Steiner
+1  A: 

Your usage of the model object instance in Page seemed odd to me right away. It is not downright incorrect but unusual to me. Some experimentation led me to a working solution, albeit without knowing the cause of the error that happened in the first place. Not many people instantiate objects directly in the DataContext assignment, which is probably why this is not a well-known (and fixed!) defect.

  1. Remove the DependencyObject base class from MyModel.
  2. Make the MyModel instance be a resource of Page, instead of instantiating it directly into the DataContext.
  3. Modify the Button_Click event handler to load the resource, instead of the named Page child object.
  4. All done!

Code snippets for the working solution follow.

Page.xaml

<UserControl.Resources>
 <my:MyModel x:Key="TheModel"/>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White" DataContext="{StaticResource TheModel}">

Page.xaml.cs

private void Button_Click(object sender, RoutedEventArgs e)
{
 ((MyModel)Resources["TheModel"]).BeginUpdateBitmap();
}

MyModel.cs

public sealed class MyModel : INotifyPropertyChanged
{

Please also include the source code with your question in the future. It would have made this quite a bit simpler.

Sander