Hi.

 

As the Headline says, I will show you how to make a Drag and Drop / Move Content control. for this example I will use a canvas and an Image. But you can easily make it more generic by using a Content Control instead of the image.

 

It is actually very simple, let’s start with the Xaml Code.

   1: <Canvas Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" HorizontalAlignment="Stretch" 
   2:         VerticalAlignment="Stretch" x:Name="ImageHolder" >
   3:     <Image Canvas.Left="0" MouseWheel="Img_MouseWheel" MouseMove="Img_MouseMove" 
   4:            MouseDown="Img_MouseDown" MouseUp="Img_MouseUp" Panel.ZIndex="0" 
   5:            Cursor="Hand" Canvas.Top="0" Height="150" Width="150" Source="sketch.jpg" 
   6:            x:Name="Img">
   7:     </Image>
   8: </Canvas>

As you can see we are using a canvas and an Image.

 

Implementing Drag and Move

to implement the drag and move we will need to use the following events:

  • MouseDown
  • MouseMove
  • MouseUp
MouseDown event

Continue Reading...

Hi

 

In my latest article I discussed Scrolling and Binding to large collections in WPF. We saw some disturbing behavior when binding a large collection to an ItemsControl. After Further Examination I found out very interesting things regarding that matter.

 

Memory Consumption

 

We saw that the application used about 500MB of Ram. Lets look at the code again:


Continue Reading...

Lately I was working on an application that had to display a large amount of objects on screen and allow filtering. I have learned that scrolling large collections was not so simple in WPF, and I definitely did not see the problems coming.

 

Memory Consumption

 

Here is an example of a simple WPF application which randomly creates 50000 Classes of type DATA in a list and displays them in an Item control:


Continue Reading...

A while back I needed to add a double click event to a control that had no such event. The solution I came up with was to wrap that control inside a UserControl and use the UserControl’s DoubleClick event.

 

One of the readers commented about a better way to do it using Command Binding, here is what David N said:

You can also do this by adding an InputBinding to the Grid, that will translate a double click to an invocation of a RoutedCommand, then you can bind that to some handler code somewhere higher in the tree. Commands seem to be a neglected part of WPF, but are really quite useful especially if there are multiple actions that should end up triggering the same code (button, toolbar button, context menu, key combination, double click in the grid..). I just used a builtin command in this sample but of course you’d probably use a custom one.

I was faced with the same problem last week so I decided to give it a shot.

 


Continue Reading...

Hi

 

A while back I wrote an article about How to sort data by manipulating the view only, This article will handle filtering the data without changing it.

 

I had a large collection that I needed to display and allow the user to filter it using many parameters. After searching for a while I found a very elegant solution:

 

What is a Predicate

what are predicates? I will Quote

Represents the method that defines a set of criteria and determines whether the specified object meets those criteria.

You can read more about it here.

 

Defining a Predicate

A predicate Is a template so you will have to specify the type for instance:


Continue Reading...

Hi

 

I was working on a Silverlight Application lately and I was in the need to open up a Popup window. and I am not talking about the regular .NET Message box. Naturally I Created a Page with some controls created a new instance of it but Saddly there was no Page.Show() method :( .

 

I know you can use the Popup Control to do a similar job (although I am not sure about the fade in and out) but I just played around and I liked what came out of it, so here is my solution to this problem.

 


Continue Reading...

Here is something I picked up while wandering the web

This one is for all you Gamers and Quake lovers. It seems that a guy named has ported the Quake engine into Silverlight!!!


Continue Reading...

small_flagsUntil a couple of years ago, most software applications were released in English. Unfortunately for us the developers, nowadays, many customers require that that the product they purchased, will be localized to a specific language (other than English). I know, for instance, that there is a European law which requires healthcare products to be localized to the European market (starting from 2009 or 2010). Because this article is about how to localize your application using string tables, I recommend you to first read about a free tool which helps you extract hard coded strings to string tables. Don’t go any further before you also read about how to generate public properties for string tables, you must read it.

Setting up a String Table

I assume that you already have some user interface which needs to be localized, I will demonstrate this process with…


Continue Reading...

Hi

In my previous post about WPF Binding Converters one of our readers (Thanks The Reddest) pointed our that a new converter instance is not created every time a call is made to the converter. I promised to test it again so here goes :)
I used the old converter code but added a static integer inside the converter to count the number of calls made to it. and then printed it out to the trace in the constructor.


Continue Reading...

In the previous month I have written an article about how to design a WPF custom context menu. I really liked that article because the outcome was very nice. Here comes the but :), as it turns out my implementation had a big disadvantage, it lacked the ability to show sub menus (an important trait in my opinion). So it was back to the drawing board for me.

After studying the WPF MenuItem Class and its Original Microsoft Template using blend. I learned some new things


Continue Reading...