M
M
Michael2020-06-04 09:03:35
WPF
Michael, 2020-06-04 09:03:35

How to get checkboxa value from Listboxa template?

Hello,
there is a base

class MeasureVariation
    {
        public int Id { get; set; }
        public string VariationName { get; set; }
        public bool IsCalc { get; set; }
        public MeasureType MeasureType { get; set; }
    }


there is a Listbox
<ListBox x:Name="lb" Height="290" ItemsSource="{Binding LineVariationList}" Margin="0, 0, 0, 10">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <WrapPanel>
                                <CheckBox
                                IsChecked="{Binding Path=IsCalc, Mode=TwoWay}" Content="{Binding Path=VariationName}" Command="{Binding CmdIsCalcChecked, Mode=TwoWay}"/>
                            </WrapPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>


viewmodel
public ObservableCollection<MeasureVariation> LineVariationList { get; set; }


I planned to do so, when you click on the checkbox, the value of the checkbox should be written to the database, or after clicking on the button. I don't understand how to get the changed state of the checkbox.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Michael, 2020-06-05
@mscrack

Issue resolved. Thanks to all.
I did this, I added a button in the view and when I click on it, a command is executed in which I go through the list and change states. I didn’t manage to do it through triggers, there is room to grow.

foreach (var Item in LineVariationList)
                        {
                            var CurrentMeasureVariation = context.MeasureVariations.FirstOrDefault(item => item.Id == Item.Id);

                            CurrentMeasureVariation.IsCalc = Item.IsCalc;

                            context.Entry(CurrentMeasureVariation).State = EntityState.Modified;
                            context.SaveChanges();
                        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question