ElementName does not work on derived UserControls?

I used the sample http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=96651&SiteID=1

of Beatriz, where a slider changes the LayoutTransform of a TreeView.

The only thing i changed was that i use "UserTreeView" instead of TreeView.

Whereas UserTreeView ist derived from TreeView.

Here is the exception:

Cannot find source for binding with reference 'ElementName=slider'.

BindingExpression:Path='Value'; DataItem=''null'';

target element is 'UserTreeView (Name='tree')'; target property is 'LayoutTransform' (type 'Transform');

Is this a bug Or is anything wrong.



Answer this question

ElementName does not work on derived UserControls?

  • Jayson Valencia

    Beatriz, I wish I had found this thread earlier. Can you confirm that this is the same bug that I am running against here: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=454274&SiteID=1

    Basically, the following xaml works when it is inside a page, but when I extract it into a usercontrol, the itemssource is not set:

    <ItemsControl ItemsSource="{Binding ElementName=lb, Path=SelectedItem, Mode=Default}" >
    <ItemsControl.Style>
    <Style TargetType="{x:Type ItemsControl}">
    <Setter Property="Template">
    <Setter.Value>
    <ControlTemplate TargetType="{x:Type ItemsControl}">
    <StackPanel Orientation="Horizontal">
    <Button>press me</Button>
    <ScrollViewer VerticalScrollBarVisibility="Auto">
    <StackPanel Orientation="Horizontal"
    IsItemsHost="True" />
    </ScrollViewer>
    </StackPanel>
    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style>
    </ItemsControl.Style>
    </ItemsControl>



  • Michael King

    Fixed in June CTP
  • ZENPook

    Hi Roland,

    That is a bug. It seems like the same issue reported in this post (I mean, different issue, but with the same cause): http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=434020&SiteID=1. Basically there are some issues with name scoping and custom controls in Beta 2 that affect binding. I will make sure I will verify your scenario when we get the fix for the bug. Hopefully you will find a fix for this on our next release.

    This kind of feedback is absolutely invaluable to us before we ship. Thanks a lot for reporting the issue!

    Bea



  • ElementName does not work on derived UserControls?