I stumbled upon a adding a content to the DropDownContent property of the RadDropDownButton. Particularly I have a problem binding a dependency property of the content element to a property up the logical tree hierarchy. I managed to reproduce the issue in small piece of XAML. It contains a window with a local value “Test” set to its Tag property. There is a TextBlock inside the DropDown button with its property Text bound to the Tag property of the window. When I run the sample I get the following error:
“System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Window', AncestorLevel='1''. BindingExpression:Path=Tag; DataItem=null; target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')”
Another identical TextBlock is placed outside of the DropDown button and its Binding works fine.
I guess that the RadDropDownButton control fails to preserve the logical tree inheritance by not callingFrameworkElement.AddLogicalChild method on the DropDownContent element (provided that the content inherits from FrameworkElement). Here is the XAML code:
<Window x:Class="WpfApplication14.MainWindow" Title="MainWindow" SizeToContent="WidthAndHeight" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" |
Tag="Test" > |
<Grid Width="200" Height="200"> |
<StackPanel HorizontalAlignment="Left"> |
<TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=Tag}" Height="22"/> |
<telerik:RadDropDownButton Content="Drop Down" Height="22" Width="200" DropDownWidth="200"> |
<telerik:RadDropDownButton.DropDownContent> |
<TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=Tag}"/> |
</telerik:RadDropDownButton.DropDownContent> |
</telerik:RadDropDownButton> |
</StackPanel> |
</Grid> |
</Window> |