Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

New Post: CheckListBox and ItemsSource

$
0
0
I want to use CheckListBox and bind its ItemsSource to an ObservableCollection.

This is the XAML:
<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:tk="http://schemas.xceed.com/wpf/xaml/toolkit"
        Title="MainWindow" Height="350" Width="525">
    <StackPanel>
        <Button Click="AddClick">Add</Button>
        <tk:CheckListBox ItemsSource="{Binding ListItems}"></tk:CheckListBox>
    </StackPanel>
</Window>
And this is the code-behind:
namespace WpfApplication1
{
    ///<summary>/// Interaction logic for MainWindow.xaml///</summary>publicpartialclass MainWindow : Window
    {
        public ObservableCollection<string> ListItems { get; set; }

        public MainWindow()
        {
            InitializeComponent();

            this.DataContext = this;

            ListItems = new ObservableCollection<string>();
        }

        privatevoid AddClick(object sender, RoutedEventArgs e)
        {
            ListItems.Add("string");
        }
    }
}
When I click the Add button in my UI, it crashes in the AddClick method with the following error:
The runtime has encountered a fatal error. The address of the error was at 0xeb40f4f4, on thread 0x1414. The error code is 0x80131623. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
Is this a bug or am I doing something wrong? My code is pretty straight forward. If I change the CheckListBox to regular ListBox everything works...

Thanks!
Dina

Viewing all articles
Browse latest Browse all 4964

Trending Articles