Alternate method to hook up properties & events - #671
Draft
cwensley wants to merge 1 commit into
Draft
Conversation
Member
Author
|
This allows us to change something like this (e.g. the Stepper control): [Handler(typeof(IHandler))]
public class Stepper : Control
{
new IHandler Handler { get { return (IHandler)bqase.Handler; } }
static Stepper()
{
RegisterEvent<Stepper>(c => c.OnStep(null));
}
public const string StepEvent = "Stepper.Step";
public event EventHandler<StepperEventArgs> Step
{
add { Properties.AddHandlerEvent(StepEvent, value); }
remove { Properties.RemoveEvent(StepEvent, value); }
}
protected void OnStep(StepperEventArgs e)
{
Properties.TriggerEvent(StepEvent, this, e);
}
[DefaultValue(StepperValidDirections.Both)]
public StepperValidDirections ValidDirection
{
get { return Handler.ValidDirection; }
set { Handler.ValidDirection = value; }
}
ICallback callback = new Callback();
protected override object GetCallback() => callback;
public new interface ICallback : Control.ICallback
{
void OnStep(Stepper widget, StepperEventArgs e);
}
protected new class Callback : Control.Callback, ICallback
{
public void OnStep(Stepper widget, StepperEventArgs e)
{
widget.Platform.Invoke(() => widget.OnStep(e));
}
}
public new interface IHandler : Control.IHandler
{
StepperValidDirections ValidDirection { get; set; }
}
}To this: public class Stepper : Control
{
public static DependencyEvent<Stepper, StepperEventArgs> StepEvent = new DependencyEvent<Stepper, StepperEventArgs>((c, e) => c.OnStep(e));
public event EventHandler<StepperEventArgs> Step
{
add { Properties.AddEvent(StepEvent, value); }
remove { Properties.RemoveEvent(StepEvent, value); }
}
protected void OnStep(StepperEventArgs e) => Properties.TriggerEvent(StepEvent, this, e);
public static DependencyProperty<Stepper, StepperValidDirections> ValidDirectionProperty = new DependencyProperty<Stepper, StepperValidDirections>(StepperValidDirections.Both);
[DefaultValue(StepperValidDirections.Both)]
public StepperValidDirections ValidDirection
{
get { return Properties.Get(ValidDirectionProperty); }
set { Properties.Set(ValidDirectionProperty, value); }
}
} |
cwensley
marked this pull request as draft
June 11, 2020 22:01
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is an experimental feature, trying to simplify the creation of new controls. In most cases this may even eliminate the need to declare an IHandler interface for the control.
This will probably be done for the 3.x series (which is a ways off)
Benefits:
Connectorin GTK (due to using static methods to wire up event handlers)ICallback/CallbackimplementationsEventManager.Register()in the static constructorsIHandlerin cases where there are no methods and only properties and/or events.Drawbacks:
Widget.Properties, accessing them may be slower (though this can be mitigated by pushing more functionality into subclasses of the native controls)Incomplete:
Style.Add<SomeHandler>(h => h.Control.NativeProperty = blah);won't work