WPF-style code

G

Giulio Petrucci

Hello there,

starting from this minimal XAML

<Window x:Class="Acme.Graph.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Border BorderBrush="Black" BorderThickness="2"></Border>
<Rectangle Grid.Column="0" Height="40" Width="40"
Fill="Black"></Rectangle>
<Canvas AllowDrop="True"></Canvas>
</Grid>
</Window>

the main window has:
- on the left side: a black square
- on right side: a canvas
I need to implement this behaviour: dragging the black square onto the
canvas, when the black square is dropped, a imilar square is drawn on
the canvas.

How would you approach the problem in a WPF-style? Triggers? Commands?
Or a lot of code-behind, like in WinForms?

Thanks in advance.
Ciao,
Giulio

--
 
A

Andy O'Neill

the main window has:
- on the left side: a black square
- on right side: a canvas
I need to implement this behaviour: dragging the black square onto the
canvas, when the black square is dropped, a imilar square is drawn on the
canvas.

How would you approach the problem in a WPF-style? Triggers? Commands? Or
a lot of code-behind, like in WinForms?

You need code.
You can't just drag and drop uielements from one parent to another without
any code.
One of your problems will be the way the visual tree works.
Once your black square has a parent it needs to be disconnected from it
before you can add it to another parent, like your canvas.

Google drag and drop smorgasbord

There is a web forum specifically aimed at wpf which you might want to ask
future questions in.
Over on social.msdn.microsoft.com/Forums
But I'll tell you the same thing over there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top