How to create a WPF popup using my thumb?

I searched for a long time and it is hard to find an example of this on the net. I have seen alternative methods for this, but I want to specifically use the thumb. In an attempt to hash the solution, I was not able to get the functionality correctly / working as I am pretty new to WPF. I would appreciate it if someone could give an example of how you can implement the above.

Greetings

+4
source share
1 answer

A Popup does not give you an obvious way to move it; you can only place it relative to the purpose of the placement. However, this gives you an additional offset in relation to the purpose of the placement and that is enough to move it anywhere.

Only markup works here, which demonstrates a draggable Popup with Thumb using Markup Programming . There is a text box with a popup that appears when the text box receives keyboard focus. The popup has text and thumb.

 <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:p="http://markupprogramming.codeplex.com/markup/programming" Height="300" Width="300"> <Grid> <StackPanel> <TextBox x:Name="textBox1" Width="200" Height="20"/> </StackPanel> <Popup Name="popup" PlacementTarget="{Binding ElementName=textBox1}" IsOpen="{Binding IsKeyboardFocused, ElementName=textBox1, Mode=OneWay}"> <StackPanel Orientation="Horizontal"> <TextBlock Background="White" Text="Sample Popup content."/> <Thumb Name="thumb" Width="20" Height="20"/> </StackPanel> <p:Attached.Operations> <p:ScriptHandler Path="@FindElement('thumb').DragDelta"> @AssociatedObject.HorizontalOffset += @EventArgs.HorizontalChange; @AssociatedObject.VerticalOffset += @EventArgs.VerticalChange; </p:ScriptHandler> </p:Attached.Operations> </Popup> </Grid> </Window> 
+4
source

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


All Articles