 |
|
 |
Hook the DragCanvas's PreviewMouseUp event and perform your selection logic there. You might want to use the DragCanvas's FindCanvasChild method to walk from the e.OriginalSource to the direct child element of the canvas.
|
|
|
|
 |
|
 |
Thanks Josh.
I’m not sure what you mean by “Hook the DragCanvas's PreviewMouseUp event”. You have the following overrived which fires when I click on an object in the canvas, but not when I click on the canvas itself:
protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
{
base.OnPreviewMouseUp(e);
if (isDragStarting)
{
// Raise event to any conumer interested in knowing that the drag is stopping
EndDragEvent();
}
// Reset the field whether the left or right mouse button was
// released, in case a context menu was opened on the drag element.
this.ElementBeingDragged = null;
}
I Added this event handler which also doesn’t fire when clicking on the canvus, but does fire when clicking on an object in the canvas:
public DragCanvas()
{
this.PreviewMouseUp += new MouseButtonEventHandler(TestOnMouseUp);
}
void TestOnMouseUp(object sender, MouseButtonEventArgs e)
{
Console.WriteLine(sender.ToString());
}
How can I get code to execute when the user clicks and open-empty space in the canvas (clicks on the canvas)?
|
|
|
|
 |
|
 |
Moondaddy,
The problem is that by default the Canvas's Background property is null. An element with a null Background does not participate in the mouse input event system. Set the DragCanvas's Background to, perhaps, Brushes.Transparent and then it will raise the PreviewMouseUp event as expected.
|
|
|
|
 |
|
 |
Hi all,
as I already stated I love your lib!
But now, I got a problem using the CenteredContentControl: I tried to adapt your XAML example to C#:
Line connectorLine = new Line();
connectorLine.Stroke = Brushes.Red;
connectorLine.StrokeThickness = 3;
CenteredContentControl ccc1 = new CenteredContentControl();
ccc1.Content = rect_top;
CenteredContentControl ccc2 = new CenteredContentControl();
ccc2.Content = rect_bottom;
Binding bind1 = new Binding();
bind1.Source = ccc1;
Binding bind2 = new Binding();
bind2.Source = ccc2;
connectorLine.SetBinding(Line.X1Property, bind1.Source.ToString());
connectorLine.SetBinding(Line.Y1Property, bind1.Source.ToString());
connectorLine.SetBinding(Line.X2Property, bind2.Source.ToString());
connectorLine.SetBinding(Line.Y2Property, bind2.Source.ToString());
DragCanvas.Children.Add(connectorLine);
DragCanvas.BringToFront(connectorLine);
The elements rect_top and rect_bottom are children of two DragCanvas elements which are children of one DragCanvas element in the main window. When I assign the content to the first CenteredContentControl ccc1, I get an error in the method OnPropertyChanged() during the 4th (?!) call of base.OnPropertyChanged(e);.
Do you know what's wrong here?
Thanks for your help...!
|
|
|
|
 |
|
 |
DaSch-Productions wrote: I get an error in the method OnPropertyChanged() during the 4th (?!) call of base.OnPropertyChanged(e);.
What is the exception's message? What is the inner-exception's message?
|
|
|
|
 |
|
 |
I get an InvalidOperationException.
The message text is (I try to translate it because I get the text in german):
"The provided element is already a logical subordinated element of another element. Accomplish a separation first."
The Inner Exception's text is null.
|
|
|
|
 |
|
|
 |
|
 |
Thanks a lot.
|
|
|
|
 |
|
 |
I've seen a lot of posts around the web that have asked about Vista's "bread crumb" explorer bar. I find that control absolutely brilliant. Unfortunately, that control in Vista is not a common control; it isn't meant for use by other applications. So how about a WPF version of the Vista bread crumb control? That would rock.
|
|
|
|
 |
|
 |
Thanks for the idea, Judah. I'll definitely consider adding it to my library. I appreciate the feedback.
:josh:
My WPF Blog[ ^]
We are what we repeatedly do. Excellence then, is not an act, but a habit. - Aristotle
|
|
|
|
 |
|
 |
Hi Josh,
Do you have any good suggestions of specific articles/tutorials to start out with for complete newb's to WPF?
thanks
"For fifty bucks I'd put my face in their soup and blow." - George Costanza ~ Web SQL Utility - asp.net app to query Access, SQL server, MySQL. Stores history, favourites.
|
|
|
|
 |
|
|
 |
|
 |
Josh,
I'm still using VS 2003. I would like to skip VS 2005 / .NET 2.0 and go straight to .NET 3.0 and WPF.
What's the best way? What tools do I need?
Thanks,
Marcel
|
|
|
|
 |
|
|
 |
|
 |
Thanks Josh - great idea btw
|
|
|
|
 |
|
 |
Thanks Nish. I hope this little initiative catches on and people use WPF.JoshSmith in their apps.
|
|
|
|
 |
|
 |
Josh Smith wrote: Thanks Nish. I hope this little initiative catches on and people use WPF.JoshSmith in their apps.
Yeah, that'd also ensure that your name is saved in code snippets for posterity
|
|
|
|
 |
|
 |
Nishant Sivakumar wrote: Yeah, that'd also ensure that your name is saved in code snippets for posterity
I suppose that's as close to immortality as a developer can get.
|
|
|
|
 |
|
 |
I like what you've done in WPF so far. I'm glad that your code is all in one Assembly now, that's a good idea. Looking forward to the new classes you add to your library!
Take care.
|
|
|
|
 |
|
 |
Thanks.
|
|
|
|
 |