0

i have a problem with reading a changed Value:

Binding in XAML:

  Text="{Binding Path=Infotext,Mode=TwoWay}"

i try to read a Value (its bound to a Textbox, Class is Ticket, ic_Tickets is a Itemscontrol with "Tickets") by:

string text=((ObservableCollection<Ticket>)ic_Tickets.ItemsSource).Where(Ticket => Ticket.id == ((MenuItem)sender).Tag.ToString()).First().Infotext;

with this (in public class Ticket:INotifyPropertyChanged i got the old bound value

public string Infotext { get
            {
                return Infotext_int;
            }


            set {
                Infotext_int = value;
             
                NotifyPropertyChanged();
            } }

but if i add a Messagebox like this:

 public string Infotext { get
            {
                return Infotext_int;
            }


            set {
                Infotext_int = value;
             MessageBox.Show("!!!"); //or inside the NotifyPropertyChanged()
                NotifyPropertyChanged();
            } }

i get the new Value ... (i want the new Value but it is not a possible way to show allways a Messagebox)

So only it sets the new Value to the Itemssource, when a Messagebox is shown oO

Notify Function:

private void NotifyPropertyChanged(String propertyName = "")
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
user3600403
  • 339
  • 1
  • 2
  • 18
  • There seems to be an awful lot of confusion here. All you should really have to do is bind the property, and then use it just like any other property. Also, who writes braces this way? – Robert Harvey Jul 09 '20 at 14:31
  • I found the Problem (Bug?), when i changing the Text and using the Contexmenu to call my Function, without clicking to a other Element it will not Update the Source - but when i call " ic_Tickets.Focus();" before i read the Itemsource it will update. – user3600403 Jul 09 '20 at 14:38
  • Then `Text="{Binding Path=Infotext, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"` should work. Still, your code is confusing. You should at least replace `(ObservableCollection)ic_Tickets.ItemsSource` by accessing the source collection. Something like `tickets.Where(...)...`. – Clemens Jul 09 '20 at 14:41
  • THX UpdateSourceTrigger=PropertyChanged fixed it for me (or using a Button not a Contextmenu – user3600403 Jul 09 '20 at 14:46

0 Answers0