tags:

views:

302

answers:

1

Hi Experts,

I have problems with bindings. I want to use a UserControl (Intellibox from codeplex) but I only get error messages in the output window. Basically I have

window grid ... stuff ... usercontrol (self written) ... stuff ... usercontrol (IntelliBox)   

In the Output window I get following stuff:

System.Windows.Data Error: 4 : Cannot find source for binding with reference 
  'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.UserControl', 
  AncestorLevel='1''. BindingExpression:Path=ShowResults; DataItem=null; 
  target element is 'Popup' (Name='IntelliboxPopup1'); 
  target property is 'IsOpen' (type 'Boolean')  

The binding in the IntelliBox control is defined as follows:

{Binding Path=ShowResults, RelativeSource={RelativeSource FindAncestor, 
 AncestorType={x:Type UserControl}}}

I guess there is a problem, cause the nesting withing usercontrols - how to I get this error fixed?

Thanks!

+1  A: 

I have two questions. First, is this a Binding that you wrote for your use, or is it something that came out-of-the-box inside the UserControl you're using? Second, are you trying to Bind to the Intellibox, or to your "self written" UserControl?

Assuming it's a Binding you wrote for your use (I don't have knowledge of Intellibox so I wouldn't know where to start for fixing it), there are a couple of solutions you might try.

First, when binding to an ancestor, try using the exact ancestor type. For instance, if you're binding to the Intellibox, use AncestorType={x:Type Intellibox}. Otherwise use AncestorType={x:Type <YourType>}. Your Binding will be less ambiguous this way.

Second, and perhaps the best answer in this case, is to bind to the control you want by name by setting x:Name="BindSource (or whatever)" on the target and using the Binding syntax:

{Binding Path=ShowResults,
         ElementName=BindSource}

-- HTH, Dusty

dustyburwell
Hi, thanks for your answer. The problem resides in the IntellBox control I tried to use (you can get it from codeplex). I will try with bind by name. Thanks again!
JerryVienna