My requirement is to show a custom UserControl as a popup. I am trying to implement this in Silverlight/MVVM using this method. But I am unable to find a way where I can pass some parameter to my popup. I went through this method to achieve it but it's somehow not working.
This is how my XAML looks like:
Behavior to button in View1. On click of this button, I am opening a popup View2:
<cmds:PopupBehavior.CustomUI>
<views:View2 CategoryID="{Binding CategoryID, Mode=TwoWay}"/>
</cmds:PopupBehavior.CustomUI>
CategoryID is a Dependency Property for View2 and is bound to a property of same name in the view model of View1. But for some reason, I always get CategoryID as 0 in View2 even though it's getting set properly in my View1 viewmodel.
Where am I going wrong?
EDIT:
Here is the dependency property code for View2:
public static readonly DependencyProperty CategoryIDProperty = DependencyProperty.Register
("CategoryID",typeof(int),typeof(View2),new PropertyMetadata(0));
public int CategoryID
{
get { return (int)GetValue(CategoryIDProperty); }
set { SetValue(CategoryIDProperty, value); }
}
The setter of the property doesn't get called for some reason.
This must be a binding issue on the first view, change your code to the below to test and see if it is:
<cmds:PopupBehavior.CustomUI>
<views:View2 CategoryID="5"/>
</cmds:PopupBehavior.CustomUI>
If your dp's setter now get's called check your output window to see why it can't bind