Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding to a UserControl's DependencyProperty
    primarykey
    data
    text
    <p>I'm trying to adapt a soltuion for the WPF toolkit's calendar from <a href="http://msdn.microsoft.com/en-us/magazine/dd882520.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/magazine/dd882520.aspx</a> but I'm having problems getting a binding on the usercontrol to work. I've tried using FindAncestor and ElementName, but I just get a binding error.</p> <p>I think it might have something to do with the tooltip and it's DataContext in the calendar. Has anyone else had this problem?</p> <pre><code>&lt;UserControl x:Class="ChickenPing.MealCalendar" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:conv="clr-namespace:ChickenPing.Converters" xmlns:wpf="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit" xmlns:primitives="clr-namespace:Microsoft.Windows.Controls.Primitives;assembly=WPFToolkit" xmlns:vsm="clr-namespace:System.Windows;assembly=WPFToolkit" xmlns:loc="clr-namespace:ChickenPing" x:Name="root"&gt; &lt;wpf:Calendar x:Name="calendar"&gt; &lt;wpf:Calendar.Resources&gt; &lt;conv:IconConverter x:Key="IconConverter"/&gt; &lt;conv:MealCalendarConverter x:Key="MealCalendarConverter" /&gt; &lt;!--LinearGradientBrush x:Key="MealBackgroundFill" StartPoint="0,0" EndPoint="0,1"&gt; &lt;GradientStop Color="" &lt;/LinearGradientBrush--&gt; &lt;/wpf:Calendar.Resources&gt; &lt;wpf:Calendar.CalendarDayButtonStyle&gt; &lt;Style TargetType="primitives:CalendarDayButton"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="primitives:CalendarDayButton"&gt; &lt;Grid&gt; &lt;!Grid.ToolTip&gt; &lt;ToolTip&gt; &lt;ToolTip.DataContext&gt; &lt;MultiBinding Converter="{StaticResource MealCalendarConverter}"&gt; &lt;Binding Path="PlacementTarget.DataContext" RelativeSource="{x:Static RelativeSource.Self}"/&gt; &lt;Binding Path="Meals"&gt; &lt;Binding.RelativeSource&gt; &lt;RelativeSource Mode="FindAncestor" AncestorType="{x:Type loc:MealCalendar}" /&gt; &lt;/Binding.RelativeSource&gt; &lt;/Binding&gt; &lt;/MultiBinding&gt; &lt;/ToolTip.DataContext&gt; </code></pre> <p>The error is:</p> <pre><code>System.Windows.Data Warning: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='MyAssembly.MyControl', AncestorLevel='1''. BindingExpression:Path=ConversionCollection; DataItem=null; target element is 'ToolTip' (Name=''); target property is 'DataContext' (type 'Object') </code></pre> <p>And the declaration for the DependencyProperty:</p> <pre><code>public static readonly DependencyProperty MealsProperty = DependencyProperty.Register("Meals", typeof(Dictionary&lt;DateTime, IEnumerable&lt;PlannedMealGroup&gt;&gt;), typeof(MealCalendar), new UIPropertyMetadata(new Dictionary&lt;DateTime, IEnumerable&lt;PlannedMealGroup&gt;&gt;())); public Dictionary&lt;DateTime, IEnumerable&lt;PlannedMealGroup&gt;&gt; Meals { get { return base.GetValue(MealsProperty) as Dictionary&lt;DateTime, IEnumerable&lt;PlannedMealGroup&gt;&gt;; } set { base.SetValue(MealsProperty, value); } } </code></pre> <p>There's another control I have where the same thing happens, so I think I may be missing something.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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