imageComponent.NET - image processing .NET assemblies

WPF UserControl inheritance

by Hong 3. October 2008 08:09

I have been working with WPF lately. There are many things I feel it becomes a little strict for me, but I guess that might be I am still new to this new thing and not fully familiar with the difference yet.

In the application I am building, I need to have a movable base UserControl, which can randomly move within the container. Then I will write several subclass to have different appearance. The first mistake I did was, I created a new UserControl (with XAML),  added those animation and transformation control in it, a little code behind, then I  felt confidence to do the subclass; however, I was wrong. 

I was not able to create another XAML file inherit from my base UserControl. I might be wrong, but I couldn't find any solution online. 

The way I did is, I created a Class file, no XAML at all. It will look like:

namespace WPFTest {

    public class MovableUserControl : System.Windows.Controls.UserControl{}

}

 Then in the inherited class, I have

<local:MovableUserControl x:Class="WPFTest.MyMovableControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="80" Width="160" xmlns:local="clr-namespace:WPFTest">

</local:MovableUserControl>

 

Now inside the XAML class, I can define the control outlook. I am not sure if I am doing the right thing though, if not, please let me know.

Next time, I will discuss how I implement the animation in my user control, which was not easy for me at the beginning, but I am happy everything ends up working now.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

WPF

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.5.0

About the author

ImageComponent.NET - image processing and watermarking .NET assemblies