3

Context :

I have a wpf window that has a variable float processTime = -1;.

This variable is passed by reference to a user control. The user control then pass the reference of the variable to a COM. The COM increments the variable.

If I put a breakpoint in my window, I can see the new variable value.

Now, I want to display it on screen.

Problem :

As far as I know, you can't bind a variable to a wpf textblock. You must use a property.

Also, I can't pass a property by ref to my function. That's precisely why I'm using a variable.

EDIT : Note that the COM job is to stream a video with directshow filters. Which means the job is not just done after the call... It's running for a long time, thus why I want to bind a variable to screen so you can see the values, live.

Cheap solution

I could do some kind of timer that updates a textblock value every second...

Dave
  • 2,774
  • 4
  • 36
  • 52

1 Answers1

3
 public float ProcessTime
 {
    get {return _processTime;}
 }


 //after you do your COM stuff call
 this.OnPropertyChanged("ProcessTime"); 
blindmeis
  • 22,175
  • 7
  • 55
  • 74
  • hmm Not sure how to do this : this.OnPropertyChanged("ProcessTime"); , doesnt compile here, need a propertychange event args – Dave Oct 07 '14 at 12:37
  • 1
    @Dave, you have to implement `INotifyPropertyChanged`, see [here](http://stackoverflow.com/q/1315621/1997232). – Sinatr Oct 07 '14 at 12:40
  • @Sinatr, from [here](http://stackoverflow.com/questions/956165/wpf-onpropertychanged-for-a-property-within-a-collection) , I see that I should implement it in my user control, not in the window. And in the set part he throws an event. I don't think I can't do that, because the user control doesn't change the value, the COM does. – Dave Oct 07 '14 at 12:47
  • if the COM has no event you can subscribe to, then the timer would be the solution. my answer just handle the binding and notification to wpf. – blindmeis Oct 07 '14 at 12:55
  • @blindmeis, Ok thanks I got it working with the timer thingy. – Dave Oct 07 '14 at 13:16