Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom control ContentProperty DataBinding
    primarykey
    data
    text
    <p>I'm running in a issue while trying to use dependency properties in objects which are parts of a collection, inside acustom control, collection identified with the "ContentProperty" attribute. Ok, that's quite unclear. Here is sample of my custom control : </p> <p>Here is my custom control basic definition :</p> <pre><code>[ContentProperty("SmarSearchScopes ")] public class SmartSearchCc : Control { List&lt;SmartSearchScope&gt; SmarSearchScopes {get;set;} (more code here) } </code></pre> <p>Here is the basic definition of a SmartSearchScope object :</p> <pre><code>public class SmartSearchScope : DependencyObject { public static readonly DependencyProperty ViewProperty =DependencyProperty.Register("View", typeof (ICollectionView), typeof (SmartSearchScope),new UIPropertyMetadata(null,OnViewChanged)); public static readonly DependencyProperty FilterColumnsProperty =DependencyProperty.Register("FilterColumns", typeof (IEnumerable&lt;ColumnBase&gt;), typeof (SmartSearchScope),new UIPropertyMetadata(null, OnFilterColumnsChanged)); public ICollectionView View { get { return (ICollectionView) GetValue(ViewProperty); } set { SetValue(ViewProperty, value); } } public IEnumerable&lt;ColumnBase&gt; FilterColumns { get { return (IEnumerable&lt;ColumnBase&gt;) GetValue(FilterColumnsProperty); } set { SetValue(FilterColumnsProperty, value); } } (more code here) } </code></pre> <p>All that for what ? Being able to pass a collection of SmartSearchScope objects via XAML like so :</p> <pre><code>&lt;SmartSearch:SmartSearchCc HorizontalAlignment="Stretch" Grid.Row="0" &gt; &lt;SmartSearch:SmartSearchScope FilterColumns="{Binding ElementName=CcyPairsConfigBlotter, Path=Columns}" View ="{Binding ElementName=CcyPairsConfigBlotter, Path=ItemsSource}"/&gt; &lt;SmartSearch:SmartSearchScope FilterColumns="{Binding ElementName=ClientConfigBlotter, Path=Columns}" View ="{Binding ElementName=ClientConfigBlotter, Path=ItemsSource}"/&gt; &lt;/SmartSearch:SmartSearchCc&gt; </code></pre> <p>'ClientConfigBlotter' and 'CcyPairsConfigBlotter' are just two ItemsControls which expose a 'Columns' and an 'ItemSource' d-property.</p> <p>The problem here is that althought my 2 SmartSearchScope objects gets instantiated, the databinding on the "View" and "FilterColumns" d-properties is not made and I never go througth the the associated callbacks.</p> <p>In addition, here is the output error message I got when creating the custom control.</p> <pre><code>System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Columns; DataItem=null; target element is 'SmartSearchScope' (HashCode=56862858); target property is 'FilterColumns' (type 'IEnumerable`1') System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=ItemsSource; DataItem=null; target element is 'SmartSearchScope' (HashCode=56862858); target property is 'View' (type 'ICollectionView') </code></pre> <p>This is obvious that I'm missing something but I can't find what.</p> <p>I must say that, in a previous version of that control, these 2 problematic d-properties where SmartSearchCc properties and that all worked just fine.</p> <p>Thanks for your help :)</p> <p>--bruno</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload