1
votes

I'm creating a WinRt app that has user controls in it's pages, and I'm using MVVM with Caliburn Micro. In the user control I have a dependency property that I'm binding to a collection in my view model, but the binding doesn't work, at least not until I change the rezolution of the simulator. I went into debug mode, and the data context of the user control is null, but when I change the rezolution and hit a breakpoint in the "SizeChanged" event, I can see that my user control is binded properly. Now I don't know what is causing this delay, because it should be binded the moment the page is loaded, but it isn't. The code is something like this:

MyPage.xaml

<MyControl Users="{Binding MyUsersCollection, Mode=TwoWay}"></MyControl>

MyControl.xaml.cs

public ObservableCollection<User> Users
    {
        get { return (ObservableCollection<User>)GetValue(UsersProperty); }
        set
        {
            SetValue(UsersProperty, value);
            LoadInfo();
        }
    }

    public static readonly DependencyProperty UsersProperty =
        DependencyProperty.Register("Users", typeof(ObservableCollection<User>), typeof(MojoMap), new PropertyMetadata(new ObservableCollection<User>()));

Can you help me figure out what is the problem here? Thank you!

1

1 Answers

0
votes

Could you try this:

public ObservableCollection<User> Users
{
    get { return (ObservableCollection<User>)GetValue(UsersProperty); }
    set
    {
        SetValue(UsersProperty, value);
    }
 }
 public static readonly DependencyProperty UsersProperty =
    DependencyProperty.Register("Users", typeof(ObservableCollection<User>), typeof(MojoMap), new PropertyMetadata(null, UsersChanged));

private static void UsersChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
    ((MojoMap) dependencyObject).LoadInfo();
}