I'm trying to show popup on DataTemplate
element TextEdit
(from DevExpress), according to this and this topics I created something like that:
<DataTemplate x:Key="SomeTemplate">
<dxe:TextEdit x:Name="SomeTextEdit" Text="{Binding DisplayText, Mode=OneWay}"
EditMode="InplaceInactive">
<dxe:TextEdit.ContextMenu>
<ContextMenu/>
</dxe:TextEdit.ContextMenu>
<Popup PlacementTarget="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type dxe:TextEdit}}}" IsOpen="{Binding IsKeyboardFocused, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type dxe:TextEdit}}, Mode=OneWay}">
<TextBlock Background="White">
<TextBlock.Text>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</TextBlock.Text>
</TextBlock>
</Popup>
</dxe:TextEdit>
</DataTemplate>
And it don't work, in Diagnostic Tool Events window I get message:
Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='DevExpress.Xpf.Editors.TextEdit', AncestorLevel='1''. BindingExpression:(no path); DataItem=null; target element is 'Popup' (Name=''); target property is 'PlacementTarget' (type 'UIElement')
Why is that?
Popup
will use differentVisualTree
and we cannot use RelativeSource binding method to find element from mainVisualTree
.Still you can setPlacementTarget
viaElementName
binding. You can use like this,