Created
January 25, 2021 01:13
-
-
Save B-Reif/1b62c0300ec2e81cb8a3e7467bd57a5c to your computer and use it in GitHub Desktop.
controlled expander sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[<Struct>] | |
type ControlledState = | |
| Writing | |
| Resetting | |
| Listening | |
type ControlledExpander() = | |
inherit Expander() | |
interface IStyleable with | |
member this.StyleKey = typeof<Expander> | |
member val ControlledState : ControlledState = Listening with get, set | |
member val OnChangeCallback : bool -> unit = ignore with get, set | |
member this.SetControlledValue(v) = | |
this.ControlledState <- Writing | |
this.IsExpanded <- v | |
this.ControlledState <- Listening | |
// For uncontrolled changes to the property, this handler resets the property | |
// to the old value, and forwards the new value to the change callback. | |
override this.OnIsExpandedChanged(e) = | |
if this.ControlledState = Listening then | |
this.ControlledState <- Resetting | |
this.IsExpanded <- e.OldValue :?> bool | |
this.ControlledState <- Listening | |
e.NewValue :?> bool |> this.OnChangeCallback | |
else if this.ControlledState = Writing then | |
base.OnIsExpandedChanged(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In this case the framework invokes
SetControlledValue
so that the controlled changes aren't intercepted.