This commit is contained in:
Erik De Bonte 2021-10-14 09:05:25 -07:00
Родитель 310b30f8f4 260f326cfd
Коммит c73e089980
5 изменённых файлов: 20 добавлений и 47 удалений

Просмотреть файл

@ -7,7 +7,7 @@ using Microsoft.StandardUI;
namespace SimpleControls.Wpf namespace SimpleControls.Wpf
{ {
public class BarChart : StandardControl<IBarChart>, IBarChart public class BarChart : StandardControl, IBarChart
{ {
public static readonly System.Windows.DependencyProperty EntriesProperty = PropertyUtils.Register(nameof(Entries), typeof(IEnumerable<ChartEntry>), typeof(BarChart), null); public static readonly System.Windows.DependencyProperty EntriesProperty = PropertyUtils.Register(nameof(Entries), typeof(IEnumerable<ChartEntry>), typeof(BarChart), null);
public static readonly System.Windows.DependencyProperty BackgroundColorProperty = PropertyUtils.Register(nameof(BackgroundColor), typeof(ColorWpf), typeof(BarChart), ColorWpf.Default); public static readonly System.Windows.DependencyProperty BackgroundColorProperty = PropertyUtils.Register(nameof(BackgroundColor), typeof(ColorWpf), typeof(BarChart), ColorWpf.Default);

Просмотреть файл

@ -7,7 +7,7 @@ using Microsoft.StandardUI;
namespace SimpleControls.Wpf namespace SimpleControls.Wpf
{ {
public class PointChart : StandardControl<IPointChart>, IPointChart public class PointChart : StandardControl, IPointChart
{ {
public static readonly System.Windows.DependencyProperty EntriesProperty = PropertyUtils.Register(nameof(Entries), typeof(IEnumerable<ChartEntry>), typeof(PointChart), null); public static readonly System.Windows.DependencyProperty EntriesProperty = PropertyUtils.Register(nameof(Entries), typeof(IEnumerable<ChartEntry>), typeof(PointChart), null);
public static readonly System.Windows.DependencyProperty BackgroundColorProperty = PropertyUtils.Register(nameof(BackgroundColor), typeof(ColorWpf), typeof(PointChart), ColorWpf.Default); public static readonly System.Windows.DependencyProperty BackgroundColorProperty = PropertyUtils.Register(nameof(BackgroundColor), typeof(ColorWpf), typeof(PointChart), ColorWpf.Default);

Просмотреть файл

@ -4,13 +4,13 @@ using System.Windows.Media;
namespace Microsoft.StandardUI.Wpf namespace Microsoft.StandardUI.Wpf
{ {
public class StandardControl<T> : System.Windows.Controls.Control, IControl, IStandardControlEnvironmentPeer where T : IControl public class StandardControl : System.Windows.Controls.Control, IControl, IStandardControlEnvironmentPeer
{ {
private StandardControlImplementation<T> _implementation; private StandardControlImplementation _implementation;
private StandardUIFrameworkElement? _buildContent; private StandardUIFrameworkElement? _buildContent;
private bool _invalid = true; private bool _invalid = true;
protected void InitImplementation(StandardControlImplementation<T> implementation) protected void InitImplementation(StandardControlImplementation implementation)
{ {
_implementation = implementation; _implementation = implementation;
} }

Просмотреть файл

@ -2,13 +2,13 @@
namespace Microsoft.StandardUI.Controls namespace Microsoft.StandardUI.Controls
{ {
public abstract class StandardControlImplementation<T> where T : IControl public abstract class StandardControlImplementation
{ {
public T Control { get; } IStandardControlEnvironmentPeer _environmentPeer;
public StandardControlImplementation(T control) public StandardControlImplementation(IStandardControlEnvironmentPeer environmentPeer)
{ {
Control = control; _environmentPeer = environmentPeer;
} }
/// <summary> /// <summary>
@ -69,7 +69,7 @@ namespace Microsoft.StandardUI.Controls
protected virtual Size MeasureOverride(Size availableSize) protected virtual Size MeasureOverride(Size availableSize)
{ {
IUIElement? buildContent = EnvironmentPeer.BuildContent; IUIElement? buildContent = _environmentPeer.BuildContent;
// By default, return the size of the content // By default, return the size of the content
if (buildContent != null) if (buildContent != null)
@ -83,7 +83,7 @@ namespace Microsoft.StandardUI.Controls
protected virtual Size ArrangeOverride(Size finalSize) protected virtual Size ArrangeOverride(Size finalSize)
{ {
IUIElement? buildContent = EnvironmentPeer.BuildContent; IUIElement? buildContent = _environmentPeer.BuildContent;
// By default, give all the space to the content // By default, give all the space to the content
if (buildContent != null) if (buildContent != null)
@ -94,7 +94,15 @@ namespace Microsoft.StandardUI.Controls
return finalSize; return finalSize;
} }
}
private IStandardControlEnvironmentPeer EnvironmentPeer => (IStandardControlEnvironmentPeer)Control; public abstract class StandardControlImplementation<T> : StandardControlImplementation where T : IControl
{
public T Control { get; }
public StandardControlImplementation(T control) : base((IStandardControlEnvironmentPeer)control)
{
Control = control;
}
} }
} }

Просмотреть файл

@ -1,35 +0,0 @@
namespace Microsoft.StandardUI.Controls
{
public class StandardUserControlImplementation<TControl> : StandardControlImplementation<TControl> where TControl : IControl
{
public StandardUserControlImplementation(TControl control) : base(control)
{
}
public IUIElement? Content { get; set; }
protected override Size MeasureOverride(Size availableSize)
{
// By default, return the size of the content
if (Content != null)
{
Content.Measure(availableSize);
return Content.DesiredSize;
}
return new Size(0.0, 0.0);
}
protected override Size ArrangeOverride(Size finalSize)
{
// By default, give all the space to the content
if (Content != null)
{
Rect finalRect = new Rect(0, 0, finalSize.Width, finalSize.Height);
Content.Arrange(finalRect);
}
return finalSize;
}
}
}