none
Binding UserControl Property RRS feed

  • General discussion

  • I have a simple user control in my project. I add an instance of it my xaml on my main page. I want to bind one of it's properties to a property in my Main page ViewModel. Something like this:

    <!-- main page xaml -->

    <

     

     

    uc:Downloader IsBusy={Binding Path=IsBusyOnMainPage, Mode=OneWay} />

    <!-- main page view model -->
    Property
    IsBusyOnMainPage
    ...

    <!-- user control code behind-->
    Property
    IsBusy
    ...



    I have tried using a Dependency Propert on my UserControl (uc) and also tried a normal property (with INotificationProperty). My trouble is it doens't want to bind properly.


     

    Thursday, December 1, 2011 8:04 PM

All replies

  • You have to use a Dependency Property inside your UserControl.

    Then you have to bind your Dependency Property to the property of the control inside your UserControl (in general we do: this.LayoutRoot.DataContext = this)

    Actually the good way is to create a custom control with a Template and use TemplateBinding.
    Thursday, December 1, 2011 8:13 PM