.net - Display Consistent Value of an Item using MVVM and WPF -


My list view controls (or the position will fit in another WPF control), I would like a TextBlock to be consistent for all items While the second text block, which changes on the basis of value in the observable clip. Here's how my code is currently kept:

XML

   item items = "{binding} Path = myithms, mode = twitter} "& gt; & Lt; ListView.ItemTemplate & gt; & Lt; DataTemplate & gt; & Lt; StackPanel Orientation = "Horizontal" & gt; & Lt; TextBlock x: name = "strVal" text = "{binding strVal}" /> & Lt; TextBlock x: name = "ConstVal" text = "{MyWinding binding} ConverVal, Mode = TwoWay}" /> & Lt; / StackPanel & gt; & Lt; / DataTemplate & gt; & Lt; /ListView.ItemTemplate> & Lt; / ListView & gt;  

Model

  Public class MyItem {public string StrVal {get; Set; }}  

see modell

  public MyVM () {Observable Collection & lt; MyItem & gt; MyItems = new reviewable collection & lt; MyItem & gt; (); For (int i = 0; i & lt; 10; i ++) myItems.Add (New MyItem {StrVal = i.ToString ()}); My items = iits; ConstVal = "1"; } Private string _constVal; Public string ConstVal {get {return_constVal; } Set {_constVal = value; OnPropertyChanged ("ConstVal"); }} Public Supervision Collection & lt; MyItem & gt; My Items {Received; Set; } Private Event PropertyChangedEventHandler PropertyChanged; Public Zero OnPropertyChanged (String Item) {If (PropertyChanged! = Zero) {PropertyChanged (This, New PropertyChangedEventArgs (Item)); }}  

}

Code Back

  this.DataContext = new MyVM ();  

StrVal replicates the property properly in the list, but ConstVal does not show the construle contained in TextBlock VM. I would think that this is because the ItemsSource of ListView is MyItems and I can not reference other variables outside of the MyItems contained in

My question is how do I get ConstVal to show values ​​in the view maudal for all lists, which will be controlled by the Observative Collection of Mytes.

To do this I can see there are 2 ways.

1) You can nominate the user's name that you are (x: name = control or whatever), and then do it.

  & lt; TextBlock x: name = "ConstVal" text = "{binding element name = control, path = datacontext. Convval, mode = dove}" />  

2) Use relative source:

  & lt; TextBlock x: name = "ConstVal" text = "{binding relative Soros = {relative serous FindAncestor, ancestor type = {X: type list view}}, path = data context. CONSTALL, MODE = DOVE}" /> 3) The way you are hunting nesting of your items (i.e. being introduced without any new datacentakes, you can do it easily.)  

Edit:

Do:

  & lt; TextBlock x: name = "ConstVal" text = "{Binding Path = Data Contains. CONSTALL, MODE = DOUBLE}" />  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -