Update StandardControl rendering, so happens after properties set

This commit is contained in:
Bret Johnson 2021-10-13 15:22:22 -04:00
Родитель 70921b1089
Коммит 5d95f637e1
2 изменённых файлов: 32 добавлений и 16 удалений

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

@ -1,26 +1,18 @@
using Microsoft.StandardUI.Controls;
using System;
using System.Windows;
using System.Windows.Media;
namespace Microsoft.StandardUI.Wpf
{
public class StandardControl<TControl> : System.Windows.Controls.Control, IControl, IStandardControlEnvironmentPeer where TControl : IControl
public class StandardControl<T> : System.Windows.Controls.Control, IControl, IStandardControlEnvironmentPeer where T : IControl
{
private StandardControlImplementation<TControl> _implementation;
private StandardControlImplementation<T> _implementation;
private StandardUIFrameworkElement? _buildContent;
private bool _invalid = true;
protected void InitImplementation(StandardControlImplementation<TControl> implementation)
protected void InitImplementation(StandardControlImplementation<T> implementation)
{
_implementation = implementation;
_buildContent = (StandardUIFrameworkElement?)implementation.Build();
if (_buildContent != null)
{
AddVisualChild(_buildContent);
AddLogicalChild(_buildContent);
}
}
void IUIElement.Measure(Size availableSize)
@ -37,11 +29,17 @@ namespace Microsoft.StandardUI.Wpf
IUIPropertyObject? IControl.GetTemplateChild(string childName)
{
throw new System.NotImplementedException();
throw new NotImplementedException();
}
protected override System.Windows.Size MeasureOverride(System.Windows.Size constraint)
{
if (_invalid)
{
Rebuild();
_invalid = false;
}
_implementation.Measure(new Size(constraint.Width, constraint.Height));
return _implementation.DesiredSize.ToWpfSize();
}
@ -88,6 +86,24 @@ namespace Microsoft.StandardUI.Wpf
return _buildContent;
}
private void Rebuild()
{
if (_buildContent != null)
{
RemoveVisualChild(_buildContent);
RemoveLogicalChild(_buildContent);
_buildContent = null;
}
_buildContent = (StandardUIFrameworkElement?)_implementation.Build();
if (_buildContent != null)
{
AddVisualChild(_buildContent);
AddLogicalChild(_buildContent);
}
}
#if false
IControlTemplate? IControl.Template
{

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

@ -2,11 +2,11 @@
namespace Microsoft.StandardUI.Controls
{
public abstract class StandardControlImplementation<TControl> where TControl : IControl
public abstract class StandardControlImplementation<T> where T : IControl
{
public TControl Control { get; }
public T Control { get; }
public StandardControlImplementation(TControl control)
public StandardControlImplementation(T control)
{
Control = control;
}