WPF flowchart generation basics 1: wpf flowchart Basics
The basic requirement for creating a WPF flowchart is to use the wpf development flowchart, which allows you to manually drag the configuration. If you have used a flow chart, you should be able to imagine the flow chart dragging configuration. Here, we will focus on the technical knowledge of wpf drag. But in fact, wpf drag has several different implementation methods. One is to move the process icon with the events such as mousedown mousemove mouseup with the corresponding mouse. Solution 2: Self-dragging event with the mouse in wpf, but this drag mainly focuses on copying information from one place to another. Instead of moving purely elements on the canvas. Solution 3 is also our focus. WPF has a special class named Thumb in the system. windows. control. primitive namespace to implement drag displacement on the canvas. This thumb control is a basic layer control that can be used to build other controls. In visual stdio, when we slide the mouse pulley, the slider on the right will appear. We can drag this slider. We can observe that by dragging this slider, the code displayed on the left will also move accordingly. Thumb's core events include DragStarted, which occurs when you press the left mouse button on the slider to start dragging. DragDelta, as long as your drag is still in progress (the left mouse button is not released ), it will happen continuously; DragCompleted -- Needless to say, this must happen after the drag operation is complete. Let's take a test with a simple example. It is mainly to show the position coordinates of the slider on the label when dragging the slider. Front-End Interface
<Grid > <Canvas Name ="g" Background="AliceBlue" HorizontalAlignment="Left" Height="100" Margin="41,72,0,0" VerticalAlignment="Top" Width="151"> <Thumb Canvas.Top ="2" Canvas.Left="2" Width="35" Height="35" DragDelta="Thumb_DragDelta"
DragStarted="Thumb_DragStarted" DragCompleted="Thumb_DragCompleted"></ Thumb> <TextBlock Canvas.Top ="2" Canvas.Left="2" x:Name ="tt" FontSize="24" ></TextBlock> </Canvas> </Grid>
Background Event Response Code
Private void Thumb_DragDelta (object sender, System. windows. controls. primitives. dragDeltaEventArgs e) {Thumb myThumb = (Thumb) sender; double nTop = Canvas. getTop (myThumb) + e. verticalChange; double nLeft = Canvas. getLeft (myThumb) + e. horizontalChange; Canvas. setTop (myThumb, nTop); Canvas. setLeft (myThumb, nLeft); tt. text = "Top:" + nTop. toString () + "\ nLeft:" + nLeft. toString ();} private void Thumb_DragStarted (object sender, DragStartedEventArgs e) {tt. text = "Haha this stuff can be dragged";} private void Thumb_DragCompleted (object sender, DragCompletedEventArgs e) {tt. text = "finally dragged to the end ";}
The original thumb control looks like a bulk of gray-headed faces. Of course, we can use controlTemplate to set his face, which is beyond the topic. The effect is as follows: