Dia
Dia

Reputation: 947

How to add a custom ListBox in C# xaml?

I had a custom class derived the listbox class. I added a MyListBox.cs file in project:

namespace WSBSync
{
    class MyListBox : ListBox
    {
        //some new methods and data members by me...
    }
}

Following this How to use a C# custom subclass in XAML, I modified my xaml file namespace like this:

<Window x:Class="WSBSync.MySettingWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:local="clr-namespace:WSBSync"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

and my custom UI here:

<local:MyListBox x:Name="sourceListBox" SelectionChanged="mySelectionChanged"/>

But I got an error during build: MyListBox doesn't exist in "clr-namespace:WSBSync" namespace.

I tried clean and rebuild my project, the error is still there. What am I missing or doing wrong?

Upvotes: 0

Views: 197

Answers (1)

user1286901
user1286901

Reputation: 319

Should be public class MyListBox : ListBox

Upvotes: 1

Related Questions