mercredi 9 août 2017

How do I set a listview to have multiple columns, a checkbox, and make it send me a command one checking

I'm relatively new to wpf and mvvm, although I've been using code behind for a month without too much trouble.

I've got a listview, and I can have it display multiple columns, or I can have it display a checkbox and a label and have it include a command message. But I'm not able to get it to do both.

From the xaml:

<ListView x:Name="TemplateListView" ItemsSource="{Binding TemplateListItems}" SelectedValue="{Binding SelectedTemplate}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <Grid>
                <CheckBox Grid.Column="0" Content="{Binding Name}" IsChecked="{Binding Use}"  Command="{Binding TemplateListChangedCommand}" />
                <TextBox BindingGroup="{Binding Message}" />
            </Grid>
        </DataTemplate>
    </ListView.ItemTemplate>

This ends up garbage.

If I use the code below, it will work perfectly but I don't get the message field this way:

<ListView x:Name="TemplateListView" ItemsSource="{Binding TemplateListItems}" SelectedValue="{Binding SelectedTemplate}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <Grid>
                <CheckBox Grid.Column="0" Content="{Binding Name}" IsChecked="{Binding Use}"  Command="{Binding TemplateListChangedCommand}" />
            </Grid>
        </DataTemplate>
    </ListView.ItemTemplate>

I tried using a grid inside the listview instead but that didn't work either.




Aucun commentaire:

Enregistrer un commentaire