RadDropDownButton.DropDownContent property breaks logical tree inheritance

6 posts, 0 answers
  1. Yavor
    Yavor avatar
    19 posts
    Member since:
    Apr 2009

    Posted 12 May 2010 Link to this post

    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 calling
    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" 
            mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"   
            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">  
                        <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=Tag}"/>  
  2. Miro Miroslavov
    Miro Miroslavov avatar
    588 posts

    Posted 15 May 2010 Link to this post

    Hello Yavor,

    Since DropDownContent is placed in Popup "over" the other elements, it's not living in the same visual tree. Which means it doesn't get the DataContext so you can't bind to it. Also you can't find Relative parents like the Window, because they are not relatives. In DropDownContent you're in different visual tree.
    For example you can bind DropDownContent to a static context that you can modify according to your needs. For reference can find the attached project.
    If you have further questions please ask us.

    All the best,
    Miro Miroslavov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
  4. tzuhsun
    tzuhsun avatar
    12 posts
    Member since:
    Mar 2011

    Posted 04 Apr 2011 Link to this post

    I have exact problem here, but now I not taking a string, instead I need to bind a control outside of RadDropDownButton, says Window. I'll take Yavor example to illustrate:

    <Window x:Class="WpfApplication14.MainWindow" Title="MainWindow" SizeToContent="WidthAndHeight"
            mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"  
            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"
                        <!-- Skip some command binding syntax -->
                        <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Window}}" />
                        <!-- End command binding syntax -->

    Have any workaround for this?
  5. tzuhsun
    tzuhsun avatar
    12 posts
    Member since:
    Mar 2011

    Posted 06 Apr 2011 Link to this post

    Has a workaround so far.

    Put the binding of object at outside of RadDropDownButton, with Loaded event, then call back that object later in ViewModel code.
  6. Inger Marie
    Inger Marie avatar
    60 posts
    Member since:
    Nov 2010

    Posted 03 May 2011 Link to this post

    I have a custom raddropdownbutton (it inherits from raddropdownbutton). It has two dependency properties which are both commands. The name (x:name) of the control is ucThis in XAML.

    The first one is used inside an itemtemplate in a ListView in the dropdowncontent. I can bind to the dependency property on ucThis.
    The second one (SendReminderByPhoneCommand) is used as command on a button in the dropdown content. Binding to the dependency property on ucThis does not work.

    When I read this post, I found out what the problem was. I am still a bit new to XAML and havent quite mastered the logical/visual tree stuff, but I figured that if the visual tree does not work the templates must be in the logical tree which seems to work.

    I solved it by setting the second in the buttons template, such as this:
     <Button Margin="2">
                            <ControlTemplate TargetType="{x:Type Button}">
                                <Button Command="{Binding SendReminderByPhoneCommand, ElementName=ucThis}"
                                        Style="{StaticResource MyButtonStyle}">
                                    <ContentPresenter Content="{TemplateBinding Content}"
  7. Allen
    Allen avatar
    50 posts
    Member since:
    Mar 2011

    Posted 17 Jun 2011 Link to this post

    ???? So how does it update the underlying viewmodel property if you pick one of the values?????
Back to Top
DevCraft banner