How to place popup in click event using silverlight 4?

I am trying to use a link button click event to create a popup with some data lists. But by default, the popup is by default located at the top left of the entire browser window.

Another control seems to need a different way to position the popup. for example, image control with a LeftButtondown / up event will be different from the click event for a button / link.

How to set popup position right below the link button?

+3
source share
1 answer

There are two approaches.

Option 1

HorizontalOffset VerticalOffset. , . : -

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        Popup popup = new Popup();
        Button b = (Button)sender;
        GeneralTransform gt = b.TransformToVisual(Application.Current.RootVisual);
        Point p = gt.Transform(new Point(0, b.ActualHeight));

        popup.HorizontalOffset = p.X;
        popup.VerticalOffset = p.Y;
        popup.Child = new Border()
        {
            Child = new TextBlock() { Text = "Hello, World!" },
            Background = new SolidColorBrush(Colors.Cyan)
        };
    }

TrannsformToVisual , , , . , .

2

.

 <StackPanel>
     <Button Content="Click Me" Click="Button_Click" />
     <Popup x:Name="popup" />
     <TextBlock Text="This text will be occluded when the popup is open" />
 </StackPanel>

: -

    private void Button_Click(object sender, RoutedEventArgs e)
    {

        popup.Child = new Border()
        {
            Child = new TextBlock() { Text = "Hello, World!" },
            Background = new SolidColorBrush(Colors.Cyan)
        };

        popup.IsOpen = !popup.IsOpen;
    }

Popup , StackPanel, . , .

+10

Source: https://habr.com/ru/post/1764534/


All Articles