views:

157

answers:

1

Hi.

I want to make a user Control in WPf with same properties and events like ListBox.(can add items , remove them , selecting ,...)

on way in windows App is use a user control which is inherit form ListBox. but in WPF I don't know how make User Control inherit from ListBox (or other WPF Control)!!!

I write this code but it had an exception

 public partial class InboxListItem : ListBox
{
    public InboxListItem()
    {
        InitializeComponent();
    }

and It's Xaml file

<UserControl 
x:Class="ListBoxControl.InboxListItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:myTypes="clr-namespace:ListBoxControl"
/>
+1  A: 

you cant make a UserControl inherit from ListBox. What you want is a CusomControl, and the xaml will traditionally live in Themes\Generic.xaml Keep in mind that you have to register the default style. Of course, you can just use the one provided by ListBox, if you want. You should check this article, it provides some good information as well as links to more articles.

Muad'Dib
thx for u help.i must those article and choose a solution.
Rev
no problem, glad to help
Muad'Dib