Browse Source

refactor initialize in control

pull/916/head
donandren 10 years ago
committed by Andrey Kunchev
parent
commit
d2f5616142
  1. 45
      src/Avalonia.Controls/Control.cs

45
src/Avalonia.Controls/Control.cs

@ -352,18 +352,28 @@ namespace Avalonia.Controls
if (--_initCount == 0 && _isAttachedToLogicalTree)
{
if (!_styled)
{
RegisterWithNameScope();
ApplyStyling();
_styled = true;
}
InitializeStylesIfNeeded();
if (!IsInitialized)
{
IsInitialized = true;
Initialized?.Invoke(this, EventArgs.Empty);
}
InitializeIfNeeded();
}
}
private void InitializeStylesIfNeeded(bool force = false)
{
if (_initCount == 0 && (!_styled || force))
{
RegisterWithNameScope();
ApplyStyling();
_styled = true;
}
}
private void InitializeIfNeeded()
{
if (_initCount == 0 && !IsInitialized)
{
IsInitialized = true;
Initialized?.Invoke(this, EventArgs.Empty);
}
}
@ -539,11 +549,7 @@ namespace Avalonia.Controls
{
base.OnAttachedToVisualTreeCore(e);
if (!IsInitialized)
{
IsInitialized = true;
Initialized?.Invoke(this, EventArgs.Empty);
}
InitializeIfNeeded();
}
/// <inheritdoc/>
@ -711,12 +717,7 @@ namespace Avalonia.Controls
{
_isAttachedToLogicalTree = true;
if (_initCount == 0)
{
RegisterWithNameScope();
ApplyStyling();
_styled = true;
}
InitializeStylesIfNeeded(true);
OnAttachedToLogicalTree(e);
}

Loading…
Cancel
Save