0
votes

I have a grid with a boolean column. I am trying to associate with anothoer checkbox control, so that when i check this checkbox my window displays a elements from grid with boolean column which is true(checked).

here is my IsChecked property

      private bool _isChecked;

      public bool IsChecked
    {
        set
        {
            _isChecked = value;

            InitializeMappedElements();

        }


        get { return _isChecked; }

    }

Here is a method that select only mapped elements from grid public ObservableCollection MappedList { get { return _mappedList; } set { _mappedList = value; } }

    private ObservableCollection<MessageFieldViewModel> _mappedList = new ObservableCollection<MessageFieldViewModel>();

     private void InitializeMappedElements()
    {

        if (_isChecked)
        {
            var transactionRuleList =
                MessageFieldVModel.GetAllMessageField().Where(ame => ame.IsMapped == _isChecked);

            _mappedList = new ObservableCollection<MessageFieldViewModel>(transactionRuleList);
            messageFields = _mappedList;
            NotifyPropertyChanged("MessageFields");

        }
    }

Associate with Grid on select

    public ObservableCollection<MessageFieldViewModel> MessageFields
       {
        set
        {
            if (_isChecked)
            {
                InitializeMappedElements();
            }

            NotifyPropertyChanged("MessageField");
        }
        get { return messageFields; }
    }

XAML

    <CheckBox  Foreground="WhiteSmoke" Content="Display only Mapped Fields" HorizontalAlignment="Center" 
                   Margin="198,35,473,74" FontFamily="Trebuchet MS" FontWeight="Bold" Grid.Column="1" 
                   IsChecked="{Binding Path= IsChecked,Mode=TwoWay}">
    </CheckBox>

when i select nothing is showing .why is this not working? thank you.

1

1 Answers

0
votes

Your logic is hard to follow and will be even harder to maintain. Instead of setting the backing field directly, use the MessageFields property and set the backing field in the setter as normal.

Having said that though, you should consider using a CollectionViewSource instead as this sounds like just a concern of the view.