After binding the command of a button to an action, I call an object which exposes a progress event.
event System.EventHandler<ProgressChangedEventArgs> ProgressChanged
I would like to display that in my XAML in the best way.
One way can be to expose two bindable fields in my VM
member x.Iteration with get() = _iteration
and set(v:int) = _iteration <- v
x.NotifyPropertyChanged <@this.Iteration@>
member x.IterationVisible with get() = _iterationVisible
and set(v:bool) = _iterationVisible <- v
x.NotifyPropertyChanged <@this.IterationVisible@>
then where I am called to perform the action I would just update the properties
member x.CompleteInference(algorithm:IGeneratedAlgorithm) =
x.IterationVisible <- true
algorithm.ProgressChanged.Add(fun args -> x.Iteration <- args.Iteration)
algorithm.run()
x.IterationVisible <- false
That leads to 2 questions :
Is there a direct way in F# to expose the progressChanged
event, without going through this intermediate Iteration
property, that can be processed by WPF ? Is it the most declarative we can get / do we always have to store some state somewhere ?
Additionaly, is there a natural way to do this 'state machine' binding entirely in XAML ?
To my knowledge there is no way to handle events in xaml, so exposing the event changes through a property is probably the best you can do.
To achieve "'state machine' binding" in xaml, you could expose the progress as a size and then bind the width of your progress bar to that property. See here for an example of this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With