Skip to content

Commit

Permalink
Make use of the virtual method CretaeControl on wpf DrawableHandler
Browse files Browse the repository at this point in the history
* Make use of the virtual method `CretaeControl` when creating the
wpf canvas for the drawable control.

* This is required to enable the extending the drawable control when
needed by a custom canvas.

* That was required in our case because we needed to provide a
custom automation peer for the wpf canvas. and we could only do that
by providing a custom canvas to the drawable.
  • Loading branch information
eng-myousif committed Apr 3, 2023
1 parent 2c752dd commit 63df69b
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/Eto.Wpf/Forms/Controls/DrawableHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@

namespace Eto.Wpf.Forms.Controls
{
public class DrawableHandler : WpfPanel<swc.Canvas, Drawable, Drawable.ICallback>, Drawable.IHandler
public class DrawableHandler : DrawableHandler<swc.Canvas, Drawable, Drawable.ICallback> { }

public class DrawableHandler<TControl, TWidget, TCallback> : WpfPanel<TControl, TWidget, TCallback>, Drawable.IHandler
where TControl : swc.Canvas
where TWidget : Drawable
where TCallback : Drawable.ICallback
{
bool tiled;
sw.FrameworkElement content;
Expand Down Expand Up @@ -51,9 +56,12 @@ public Size TileSize
}
}

class EtoMainCanvas : swc.Canvas
public class EtoMainCanvas<TTControl, TTWidget, TTCallback> : swc.Canvas
where TTControl : swc.Canvas
where TTWidget : Drawable
where TTCallback : Drawable.ICallback
{
public DrawableHandler Handler { get; set; }
public DrawableHandler<TTControl, TTWidget, TTCallback> Handler { get; set; }

protected override void OnMouseDown(sw.Input.MouseButtonEventArgs e)
{
Expand Down Expand Up @@ -111,7 +119,7 @@ protected override sw.Size ArrangeOverride(sw.Size arrangeSize)
class EtoTile : sw.FrameworkElement
{
Rectangle bounds;
public DrawableHandler Handler { get; set; }
public DrawableHandler<TControl, TWidget, TCallback> Handler { get; set; }

public Rectangle Bounds
{
Expand Down Expand Up @@ -163,18 +171,29 @@ public override void OnUnLoad(EventArgs e)
UnRegisterScrollable();
}

public void Create()
protected override TControl CreateControl()
{
Control = new EtoMainCanvas
return new EtoMainCanvas<TControl, TWidget, TCallback>
{
Handler = this,
SnapsToDevicePixels = true,
FocusVisualStyle = null,
Background = swm.Brushes.Transparent
};
} as TControl;
}

protected override void Initialize()
{
base.Initialize();

Control.Loaded += Control_Loaded;
}

public void Create()
{
CreateControl();
}

public void Create(bool largeCanvas)
{
AllowTiling = largeCanvas;
Expand Down

0 comments on commit 63df69b

Please sign in to comment.