Skip to main content

Microsoft Silverlight

Answered Question User control bindingRSS Feed

(0)

mpellegrin
mpellegrin

Member

Member

58 points

19 Posts

User control binding

Previously (Beta1), I was able to create a couple of user controls with dependency properties, place them in page.xaml, bind one dependency property to another, set the datacontext in the code behind and I was off to the races.  However, since I upgraded my project to Beta 2 I get a "Value does not fall within expected range" exception. 

Is this a bug/feature?  Is there a workaround? 

I can't post my exact code, but if my premise is not clear, I could make a short example.

 

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Answered Question

Re: User control binding

Unfortunately this is a bug... What you can do is to create a helper class with intermediate properties. Something like this:

public class Helper : INotifyPropertyChanges

{

public string Name { get; set; }

}

<TextBlock x:Name="tb1" Text="{Binding Name}"/>

<TextBox x:Name="tb2" Text="{Binding Name, Mode=TwoWay}"/>

Helper helper = new Helper();

tb1.DataContext = helper;

tb2.DataContext = helper;

 

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

mpellegrin
mpellegrin

Member

Member

58 points

19 Posts

Re: User control binding

This is exactly what I wound up doing.  In fact, now that i have implemented this I prefer this method to binding the controls directly to each other as it seems to eliminate some circular dependencies I was encountering.

 Thanks for the response.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities