c# - Updating WPF labels from static object -


I am trying to get this job done all day. I am trying to learn C # and write BlackJack programs. I have never worked with WPF before and everything about it is extremely confusing and frustrating. I think I try to update with a static example of a viewmodel class (BlackjackViewModel) Three labels on my window.

  & lt; Label X: Name = "lblPlayerTotal" content = "{binding source = {x: static classes: BlackjackViewModel.Instance}, path = PlayerTotal, UpdateSourceTrigger = PropertyChanged}" HorizontalAlignment = "Left" margin = "10,264,0,0" vertical alignment = "Top" width = "38" /> & Lt; Label X: Name = "lblDealerTotal" content = "{binding source = {x: static classes: BlackjackViewModel.Instance}, path = DealerTotal, UpdateSourceTrigger = PropertyChanged}" HorizontalAlignment = "left" margin = "10,160,0,0" vertical alignment = "Top" /> & Lt; Label X: name = "lblCardsRemaining" content = "{binding source = {x: static classes: BlackjackViewModel.Instance}, path = CardsRemaining, UpdateSourceTrigger = PropertyChanged}" HorizontalAlignment = "left" margin = "584,10,0, 0 "Vertical element =" top "/>  

I can not find anything to show, the labels are only empty. According to Debugger Blackjack View Model, the property is sending events by changing but as far as I am not saying anything is listening. Viewloadal properties look like this:

  Public Internet dealer {Receipt {return dealer total; } Set {dealerTotal = value; OnPropertyChanged ("DealerTotal"); }}  

And when viewmodel is updated it is sending events, a breakpoint on OnPropertyChanged will be triggered.

I tried to rearrange my code to not make the BlackjackViewModel instance stable and that either did not help it was difficult because I have an Event Listener set up which updates the count of remaining cards of View MODEL When a card deck is dealt with, I have to comment on it. It still did not work with the following XAML:

  & lt; Label X: name = "lblPlayerTotal" DataContext = "blackjackViewModel" content = "{PlayerTotal binding}" HorizontalAlignment = "left" margin = "10,264,0,0" vertical alignment = "top" width = "38" /> & Lt; Label X: Name = "lblDealerTotal" DataContext = "blackjackViewModel" content = "{DealerTotal binding}" HorizontalAlignment = "left" margin = "10,160,0,0" VerticalAlignment = "top" /> & Lt; Label X: name = "lblCardsRemaining" DataContext = "blackjackViewModel" content = "{CardsRemaining binding}" HorizontalAlignment = "left" margin = "584,10,0,0" VerticalAlignment = "top" />  

How do I actually update labels when updating the visual model update?

Update: With the correct fixed singleton setup, the label number is 0, not empty. See here is a model when an asset is updated, the debugger breaks on a breakpoint set which is set to OnPropertyChanged. No compulsive errors are found in the output view. I will download a WPF tracer.

  using the system; Using System.Collections.Generic; Using System.Linq; Using System.Text; System usage threading. Task; Using System.ComponentModel; Named Location Blackjack Game {Class Blackjack View Model: INotifyPropertyChanged {Private Static Blackjack View Model __instance = null; Private Ent dealer; Private players; Private int Card Remanning; Public Event Threaded ChangedEventHandler Property changed; Stable blackjack view model () {__instance = new blackjack view model (); } Learn about public et cards {Getting a return card; } Set {cardsRemaining = value; OnPropertyChanged ("CardsRemaining"); }} Public Full Failure {Receive {Return Player Overall; } Set {playerTotal = value; OnPropertyChanged ("PlayerTotal"); }} Public Entity Dealer Total (Receipt {return dealer total;} set {dealerTotal = value; OnPropertyChanged ("DealerTotal");}} Private Zero OnPropertyChanged (string propertyName) {If (PropertyChanged! = Zero) property changed , New PropertyChangedEventArgs (propertyName));} Public Static Blackjack View Model Instance {get {return __instance;}}}}  


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -