|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
Announcements
Services
Chapters
Feature Zones
|
IntroductionIn the article, "Very simple WPF Drag and Drop Sample without Win32 Calls", I stated that because of not using Win32 calls, the resulting code should also work in the browser under partial trust. Well... I was wrong. It turned out that Using the CodeTo use the code, simply unzip the file, start the project, compile and run the application. There are two interesting things I had to figure out in order to make the application work in a browser: making sure that the picture of the cursor is visible and adopts a shape that we want. Both are implemented in To make the cursor visible, we simply do: Mouse.SetCursor(Cursors.Hand);
There is a problem that remains, however: I wanted the cursor to become a rectangle and there were no rectangle shapes among <Rectangle
Name="CursorRectangle"
Height="10"
Width="20"
Visibility="Hidden">
<Rectangle.Fill>
<SolidColorBrush Color="Blue"
Opacity="0.35"/>
</Rectangle.Fill>
</Rectangle>
The following code ensures that the cursor rectangle does not move outside of the Point p = e.GetPosition(ListView1); // get the location of the mouse pointer
// get the boundaries of the ListView control (the cursor should not
// be allowed to go beyond those boundaries
Rect bounds = VisualTreeHelper.GetDescendantBounds(ListView1);
// set the vertical coordinate of the cursor to
// coincide with the current mouse vertical coordinate
// as long as we are still within the boundaries of the
// ListView control
if ( (bounds.Top < p.Y) && (bounds.Bottom > p.Y))
{
Canvas.SetTop(CursorRectangle, p.Y);
}
// set the vertical coordinate of the cursor to
// coincide with the current mouse horizontal coordinate
// as long as we are still within the boundaries of the
// ListView control
if ((bounds.Left < p.X) && (bounds.Right > p.X))
{
Canvas.SetLeft(CursorRectangle, p.X);
}
The rest of the code is very similar to that of "Very simple WPF Drag and Drop Sample without Win32 Calls" article. History
|
|||||||||||||||||||||||||||||||||||