0

I thought this to be straightforward, but for some reason my Checkbox gets converted to a string.

<UserControl x:Class="WpfApp1.Components.ExampleComponent"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WpfApp1.Components"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid>
        <ListView ItemsSource="{Binding OtherItems}">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Box}"/>
                </GridView>
            </ListView.View>
        </ListView>
    </Grid>
</UserControl>
using System.Collections.ObjectModel;
using System.Windows.Controls;

namespace WpfApp1.Components
{

    public class MyItem
    {
        private bool _checked;
        public bool IsChecked
        {
            get { return _checked; }
            set { _checked = value; }
        }

        public CheckBox Box
        {
            get { return new CheckBox() { IsChecked = IsChecked };}
        }

        public MyItem(bool isChecked)
        {
            IsChecked = isChecked;
        }
    }

    public partial class ExampleComponent : UserControl
    {
        private ObservableCollection<MyItem> _otherItems;

        public ObservableCollection<MyItem> OtherItems
        {
            get { return _otherItems; }
            set { _otherItems = value; }
        }

        public ExampleComponent()
        {            
            _otherItems = new ObservableCollection<MyItem>();
            InitializeComponent();
            DataContext = this;

            OtherItems.Add(new MyItem(true));
            OtherItems.Add(new MyItem(false));
        }
    }
}

The ListView contains the following items:

System.Windows.Controls.CheckBox Content: IsChecked:True  
System.Windows.Controls.CheckBox Content: IsChecked:False

So clearly the binding works, but how can I get it to render the Checkbox (or any other Control for that matter).

infinitezero
  • 1,610
  • 3
  • 14
  • 29

0 Answers0