I want to show a flyout at a specific place.
The place of FrameworkElements are based on the panel that you are using to hold them. If you want to show your flyout based on a FrameworkElement being placed in a specific place, you can use Canvas to position your FrameworkElement.
I want to specify a placement target element in XAML, but I want to make sure I am using the "lightest" element possible.
Flyout.ShowAt takes FrameworkElement as it's placement target. So I think the "lightest" element would be an empty custom FrameworkElement like below:
public class MyElement:FrameworkElement
And you can put it into XAML and use Canvas to position it:
<Button Name="btnClick" Canvas.Left="50" Canvas.Top="500" Click="btnClick_Click">Click Me</Button>
<local:MyElement x:Name="myEle" Canvas.Left="100" Canvas.Top="100"></local:MyElement>
public sealed partial class MainPage : Page
private void btnClick_Click(object sender, RoutedEventArgs e)
Flyout flyout = new Flyout();
TextBlock tbContent = new TextBlock
Text= "this is a flyout content"
flyout.Content = tbContent;
Grid is a pretty light element, it's just a simple
Panel-derived class without any child elements.
Button is a
Control, meaning it has a template which will create many child elements that make up its visual appearance.
Are you saying you want to use a dummy element just for the purpose of specifying the position of the flyout which you will show programmatically? If you want to avoid the element altogether, then maybe a
Popup would be a better choice.