Skip to content

Commit

Permalink
Move ControlRecyclingProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
wieslawsoltes committed Sep 23, 2024
1 parent f4322c5 commit d75c9b8
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 35 deletions.
3 changes: 1 addition & 2 deletions samples/DockMvvmSample/App.axaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:DockMvvmSample"
xmlns:ids="using:Dock.Settings"
xmlns:idc="using:Dock.Avalonia.Controls"
xmlns:idcr="using:Dock.Avalonia.Controls.Recycling"
xmlns:core="using:Dock.Model.Core"
Expand All @@ -19,7 +18,7 @@
<Application.Styles>

<Style Selector="idc|DockControl">
<Setter Property="(ids:DockProperties.ControlRecycling)" Value="{StaticResource ControlRecyclingKey}" />
<Setter Property="(idcr:ControlRecyclingDataTemplate.ControlRecycling)" Value="{StaticResource ControlRecyclingKey}" />
</Style>

<Style Selector="idc|DocumentControl">
Expand Down
3 changes: 1 addition & 2 deletions samples/DockXamlSample/App.axaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="DockXamlSample.App"
xmlns:ids="using:Dock.Settings"
xmlns:idc="using:Dock.Avalonia.Controls"
xmlns:idcr="using:Dock.Avalonia.Controls.Recycling"
Name="Dock Avalonia Demo"
Expand All @@ -24,7 +23,7 @@
</Style>

<Style Selector="idc|DockControl">
<Setter Property="(ids:DockProperties.ControlRecycling)" Value="{StaticResource ControlRecyclingKey}" />
<Setter Property="(idcr:ControlRecyclingDataTemplate.ControlRecycling)" Value="{StaticResource ControlRecyclingKey}" />
</Style>

</Application.Styles>
Expand Down
3 changes: 1 addition & 2 deletions samples/Notepad/App.axaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Notepad"
xmlns:ids="using:Dock.Settings"
xmlns:idc="using:Dock.Avalonia.Controls"
xmlns:idcr="using:Dock.Avalonia.Controls.Recycling"
x:Class="Notepad.App"
Expand All @@ -23,7 +22,7 @@
<StyleInclude Source="avares://Dock.Avalonia/Themes/DockFluentTheme.axaml" />

<Style Selector="idc|DockControl">
<Setter Property="(ids:DockProperties.ControlRecycling)" Value="{StaticResource ControlRecyclingKey}" />
<Setter Property="(idcr:ControlRecyclingDataTemplate.ControlRecycling)" Value="{StaticResource ControlRecyclingKey}" />
</Style>

</Application.Styles>
Expand Down
33 changes: 32 additions & 1 deletion src/Dock.Avalonia/Controls/Recycling/RecylingDataTemplate.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using Avalonia.Data;
using Dock.Model.Core;
using Dock.Settings;

Expand All @@ -11,6 +12,16 @@ namespace Dock.Avalonia.Controls.Recycling;
/// </summary>
public class ControlRecyclingDataTemplate : AvaloniaObject, IRecyclingDataTemplate
{
/// <summary>
/// Defines the ControlRecycling attached property.
/// </summary>
public static readonly AttachedProperty<IControlRecycling?> ControlRecyclingProperty =
AvaloniaProperty.RegisterAttached<ControlRecyclingDataTemplate, Control, IControlRecycling?>(
"ControlRecycling",
null,
true,
BindingMode.TwoWay);

/// <summary>
///
/// </summary>
Expand All @@ -26,6 +37,26 @@ public Control? Parent
set => SetValue(ParentProperty, value);
}

/// <summary>
/// Gets the value of the ControlRecycling attached property on the specified control.
/// </summary>
/// <param name="control">The control.</param>
/// <returns>The ControlRecycling attached property.</returns>
public static IControlRecycling? GetControlRecycling(AvaloniaObject control)
{
return control.GetValue(ControlRecyclingProperty);
}

/// <summary>
/// Sets the value of the ControlRecycling attached property on the specified control.
/// </summary>
/// <param name="control">The control.</param>
/// <param name="value">The value of the ControlRecycling property.</param>
public static void SetControlRecycling(AvaloniaObject control, IControlRecycling? value)
{
control.SetValue(ControlRecyclingProperty, value);
}

/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -59,7 +90,7 @@ public bool Match(object? data)
return null;
}

var controlRecycling = DockProperties.GetControlRecycling(parent);
var controlRecycling = ControlRecyclingDataTemplate.GetControlRecycling(parent);
if (controlRecycling is not null)
{
return controlRecycling.Build(data, existing, parent) as Control;
Expand Down
3 changes: 2 additions & 1 deletion src/Dock.Model.Avalonia/Controls/TemplateHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using Avalonia.Markup.Xaml.Templates;
using Dock.Avalonia.Controls.Recycling;
using Dock.Settings;

namespace Dock.Model.Avalonia.Controls;
Expand All @@ -16,7 +17,7 @@ internal static class TemplateHelper
return null;
}

var controlRecycling = DockProperties.GetControlRecycling(parent);
var controlRecycling = ControlRecyclingDataTemplate.GetControlRecycling(parent);
if (controlRecycling is not null)
{
if (controlRecycling.TryGetValue(content, out var control))
Expand Down
1 change: 1 addition & 0 deletions src/Dock.Model.Avalonia/Dock.Model.Avalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<Import Project="..\..\build\System.Text.Json.props" />

<ItemGroup>
<ProjectReference Include="..\Dock.Avalonia\Dock.Avalonia.csproj" />
<ProjectReference Include="..\Dock.Model\Dock.Model.csproj" />
<ProjectReference Include="..\Dock.Settings\Dock.Settings.csproj" />
</ItemGroup>
Expand Down
27 changes: 0 additions & 27 deletions src/Dock.Settings/DockProperties.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Data;
using Dock.Model.Core;

namespace Dock.Settings;

Expand All @@ -10,12 +9,6 @@ namespace Dock.Settings;
/// </summary>
public class DockProperties : AvaloniaObject
{
/// <summary>
/// Defines the ControlRecycling attached property.
/// </summary>
public static readonly AttachedProperty<IControlRecycling?> ControlRecyclingProperty =
AvaloniaProperty.RegisterAttached<DockProperties, Control, IControlRecycling?>("ControlRecycling", null, true, BindingMode.TwoWay);

/// <summary>
/// Defines the IsDockTarget attached property.
/// </summary>
Expand Down Expand Up @@ -46,26 +39,6 @@ public class DockProperties : AvaloniaObject
public static readonly StyledProperty<bool> IsDropEnabledProperty =
AvaloniaProperty.RegisterAttached<DockProperties, Control, bool>("IsDropEnabled", true, true, BindingMode.TwoWay);

/// <summary>
/// Gets the value of the ControlRecycling attached property on the specified control.
/// </summary>
/// <param name="control">The control.</param>
/// <returns>The ControlRecycling attached property.</returns>
public static IControlRecycling? GetControlRecycling(AvaloniaObject control)
{
return control.GetValue(ControlRecyclingProperty);
}

/// <summary>
/// Sets the value of the ControlRecycling attached property on the specified control.
/// </summary>
/// <param name="control">The control.</param>
/// <param name="value">The value of the ControlRecycling property.</param>
public static void SetControlRecycling(AvaloniaObject control, IControlRecycling? value)
{
control.SetValue(ControlRecyclingProperty, value);
}

/// <summary>
/// Gets the value of the IsDockTarget attached property on the specified control.
/// </summary>
Expand Down

0 comments on commit d75c9b8

Please sign in to comment.