November 1, 2007
Let say that you have a custom control that uses the command ApplicationCommands.Copy, and you expects that when you press Ctrl+C the command is executed, so far so good.
Now you want to wrap your control with ScrollViewer, that’s ok.
And you expect that the Ctrl+C will be handled, yes?
Well… NOOOOO!
Why! Because ScrollViewer overrides the OnKeyDown method and it’s preventing it to bubble any further.
Not an expected behavior in my opinion.
What to do? Set the Focusable property of the ScrollViewer to false, and it’s done.
1 Comment |
.Net, C#, WPF | Tagged: .Net 3.0, C#, WPF |
Permalink
Posted by andresd
October 8, 2007
I needed a type of BitmapSource that allows me to embed an image inside a XAML file. WPF has a number of derived BitmapSource classes, each one for its specialized task, one specific, BitmapImage, allows you to load images using XAML, but BitmapImage refer to external images in XAML files and does not embed images in a XAML file.
So I decided to create my own class to achieve the task.
What did I do?
- A BitmapSource derived class that expose a property with the bitmap info and can act as a reference to another BitmapSource.
- A container struct, BitmapInfo, to hold all the information needed to reconstruct the image, pixel array, size, format, etc.
- A TypeConverter that convert BitmapInfo to a serialized byte64 string and vice versa.
Using the EmbeddedBitmapSource is seamless as using any other derived BitmapSource class. For example:
Image myImage = new Image();
BitmapImage bmpImage = new BitmapImage( new Uri( “someimage.jpg” ) );
myImage.Source = new EmbeddedBitmapSource( bmpImage );
I included the sources with a sample application that let you save the image into a XAML file (the XAML file can be found after saving where the assembly is) and later to load it.

On the upper right side is the original image and on the lower part of the window is the embedded image that was loaded from the XAML file.
Source code (VS2008 project) can be downloaded from here (Remember to change the .DOC extension to .ZIP)
By the way, I took the picture some year ago in Chile near Puerto Tranquilo. In Lake General Carrera are marble caves formations, called the Capilla de marmol and Catedral de marmol that were carved by water over time. One of those from a specific angle a dog’s head can be seen.
3 Comments |
.Net, C#, WPF, XAML | Tagged: .Net 3.0, BitmapSource, C#, WPF, XAML |
Permalink
Posted by andresd