What am I doing wrong with my ItemsControl & databinding?

Posted by Joel on Stack Overflow See other posts from Stack Overflow or by Joel
Published on 2010-06-01T19:18:53Z Indexed on 2010/06/01 19:23 UTC
Read the original article Hit count: 169

I'm reworking my simple hex editor to practice using what I've recently learned about data binding in WPF. I'm not sure what I'm doing wrong here.

As I understand it, for each byte in the collection "backend" (inherits from ObservableCollection), my ItemsControl should apply the DataTemplate under resources. This template is just a textbox with a binding to a value converter. So I'm expecting to see a row of textboxes, each containing a string representation of one byte. When I use this XAML, all I get is a single line of uneditable text, which as far as I can tell doesn't use a textbox. What am I doing wrong?

I've pasted my XAML in below, with the irrelevant parts (Menu declaration, schema, etc) removed.

<Window ...>
        <Window.Resources>
            <local:Backend x:Key="backend" />
            <local:ByteConverter x:Key="byteConverter" />
            <DataTemplate DataType="byte">
                <TextBox Text="{Binding Converter={StaticResource byteConverter}}" />                    
            </DataTemplate>
        </Window.Resources>
        <StackPanel>
            <ItemsControl ItemsSource="{Binding Source={StaticResource backend}}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>
        </StackPanel>
    </Window>

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf