mercredi 10 mars 2021

Get CheckBox Content with Databinding in C# ListView Checkbox

Coming from python and need to translate some old app i made to C#. I have a ListView with Checkboxes. XAML

<ListView Name ="spored" SelectionMode="Multiple" HorizontalAlignment="Left" VerticalAlignment="Stretch" Margin="10,10,10,10" Width="750">
        <ListView.View>
            <GridView>
                <GridViewColumn Header="data">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox Content="{Binding Name}" IsChecked="{Binding CheckedShow, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
           </GridView>
        </ListView.View>

In code i have everything i need to populate this Listview and it works great.

    public class Show 
        {
            public bool CheckedShow { get; set; } //listview checkbox

            public string Name { get; set; } //listview checkbox content
        }

public List<Show> showList = new List<Show>();

private void ShowSpored_Click(object sender, RoutedEventArgs e)
{
        //here i have some foreeach loop that populates showList
        foreach(...)
        {
        .
        .
        .
        showList.Add(new Show() { CheckedShow = false, Name = infoKey });
        }
    
//after loop i populate Listview with
spored.ItemsSource = showList;
}

Now what i need to achieve and have NO idea how is the following. While list is populated i need to run some code on checked Content. I figured i need to do this with INotifyPropertyChanged.PropertyChanged Event But for the noob that i am i can't seem to manage to get Checked Content...

public class Content : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
.
.
.
}

Help please!!!




Aucun commentaire:

Enregistrer un commentaire