Matthew Finlay
Matthew Finlay

Reputation: 3464

Creating a custom ItemContainerStyle for a List ItemsSource

I'm trying to create a custom ItemContainerStyle for a ListView so that the text displayed is selectable. I'm looking to set the ItemsSource to a List<string>. If I were binding to a List<Person> (with property Name) I could do

<ListView.ItemContainerStyle>
    <Style TargetType="{x:Type ListViewItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListViewItem">
                  <StackPanel>
                    <TextBox Text="{Binding Path=Name}">
                  </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ListView.ItemContainerStyle>

How do I specify the binding for a List<T>?

Upvotes: 0

Views: 773

Answers (1)

Emond
Emond

Reputation: 50682

Just <TextBox Text="{Binding Mode=OneWay}"> will do.

Upvotes: 1

Related Questions