Question

I'm a beginner in XAML and C# I have the code below and I can't figure out what to modify to solve these two errors.

Requested value 'PropertyChanged' was not found.

and

'Cautare.get' must declare a body because it is not marked abstract, extern, or partial

Here is the XAML

<TextBox x:Name="textbutton1" Text="{Binding Cautare, UpdateSourceTrigger=PropertyChanged}"/>
<ListBox Grid.Row="1" x:Name="ListBox" Margin="0,0,-12,0" ItemsSource="{Binding Sursa.View}">

and the code-behind

public partial class MainPage : PhoneApplicationPage
    {
        public CollectionViewSource Sursa { get; set; }
        public string Cautare { get;
                set
                {
                    if (!string.IsNullOrEmpty(Cautare))
                    Filtreaza();
                    Sursa.View.Refresh(); 
                }
        }
        private void Filtreaza()
        {
            Sursa.Filter -= new FilterEventHandler(Filtru);
            Sursa.Filter += new FilterEventHandler(Filtru);
        }
        private void Filtru(object sender, FilterEventArgs e)
        {
            var src = e.Item as Rind;
            if (src == null) e.Accepted = false;
            else if (src.Text != null && !src.Text.Contains(Cautare)) e.Accepted = false;
        }
        public ObservableCollection<Rind> Lista { get; set; }

        public MainPage()
        {
            Lista = new ObservableCollection<Rind>
                        {
                            new Rind { Text = "abcd"},
                            new Rind { Text = "asdf"},
                            new Rind { Text = "asdzx"},
                            new Rind { Text = "adffgd"},
                            new Rind { Text = "asdfgea"},
                        };
            InitializeComponent();
            Sursa = new CollectionViewSource();
            Sursa.Source = Lista;
            DataContext = this;
        }
        public class Rind
        {
            public string Text { get; set; }
        }
    }

I've already read the other similar questions about CollectionViewSource and binding.

My intuition says this is a common issue but I've entered the brain-blocked-loop after two hours of testing and cannot "see" it clearly anymore. So I'm asking for help. Thank you!

Was it helpful?

Solution

hey @acadea first you have understand the basics .like how properties really worked and defined your error "Cautare.get' must declare a body because it is not marked abstract, extern, or partial" is because of not defining get of Cautare property but you are defining its set. so Define Cautare like this..

 public string Cautare { get{ return SomeStringHere ;}
            set
            {  // you can set some value here
                if (!string.IsNullOrEmpty(Cautare))
                Filtreaza();
                Sursa.View.Refresh(); 
            }
    }

second error is due to not implentation of propertychanged in your code but you are using it in your textbloack..the problem here is you have to also study about the databinding basics.. hope it give a way to start..on your problem..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top