Skip to content

Commit

Permalink
Merge pull request #371 from wieslawsoltes/BindingFixes
Browse files Browse the repository at this point in the history
Binding fixes
  • Loading branch information
wieslawsoltes authored Nov 12, 2024
2 parents ec36430 + 7509831 commit 9034af1
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 146 deletions.
10 changes: 1 addition & 9 deletions src/Avalonia.Controls.Recycling/ControlRecycling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ public void Add(object data, object control)

if (TryToUseIdAsKey && data is IControlRecyclingIdProvider idProvider)
{
#if DEBUG
Console.WriteLine($"Build: {data}, Id='{idProvider.GetControlRecyclingId()}'");
#endif
if (!string.IsNullOrWhiteSpace(idProvider.GetControlRecyclingId()))
{
key = idProvider.GetControlRecyclingId();
Expand All @@ -84,9 +81,6 @@ public void Add(object data, object control)

if (TryGetValue(key, out var control))
{
#if DEBUG
Console.WriteLine($"[Cached] {key}, {control}");
#endif
return control;
}

Expand All @@ -99,9 +93,7 @@ public void Add(object data, object control)
}

Add(key, control);

Check warning on line 95 in src/Avalonia.Controls.Recycling/ControlRecycling.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

Possible null reference argument for parameter 'data' in 'void ControlRecycling.Add(object data, object control)'.

Check warning on line 95 in src/Avalonia.Controls.Recycling/ControlRecycling.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

Possible null reference argument for parameter 'data' in 'void ControlRecycling.Add(object data, object control)'.

Check warning on line 95 in src/Avalonia.Controls.Recycling/ControlRecycling.cs

View workflow job for this annotation

GitHub Actions / Build ubuntu-latest

Possible null reference argument for parameter 'data' in 'void ControlRecycling.Add(object data, object control)'.

Check warning on line 95 in src/Avalonia.Controls.Recycling/ControlRecycling.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

Possible null reference argument for parameter 'data' in 'void ControlRecycling.Add(object data, object control)'.

Check warning on line 95 in src/Avalonia.Controls.Recycling/ControlRecycling.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

Possible null reference argument for parameter 'data' in 'void ControlRecycling.Add(object data, object control)'.

Check warning on line 95 in src/Avalonia.Controls.Recycling/ControlRecycling.cs

View workflow job for this annotation

GitHub Actions / Build windows-latest

Possible null reference argument for parameter 'data' in 'void ControlRecycling.Add(object data, object control)'.

Check warning on line 95 in src/Avalonia.Controls.Recycling/ControlRecycling.cs

View workflow job for this annotation

GitHub Actions / Build macos-latest

Possible null reference argument for parameter 'data' in 'void ControlRecycling.Add(object data, object control)'.

Check warning on line 95 in src/Avalonia.Controls.Recycling/ControlRecycling.cs

View workflow job for this annotation

GitHub Actions / Build macos-latest

Possible null reference argument for parameter 'data' in 'void ControlRecycling.Add(object data, object control)'.

Check warning on line 95 in src/Avalonia.Controls.Recycling/ControlRecycling.cs

View workflow job for this annotation

GitHub Actions / Build macos-latest

Possible null reference argument for parameter 'data' in 'void ControlRecycling.Add(object data, object control)'.
#if DEBUG
Console.WriteLine($"[Added] {key}, {control}");
#endif

return control;
}

Expand Down
13 changes: 9 additions & 4 deletions src/Dock.Avalonia/Controls/ProportionalDockControl.axaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="using:Dock.Avalonia.Converters"
xmlns:core="using:Dock.Model.Core">
xmlns:core="using:Dock.Model.Core"
xmlns:dmc="using:Dock.Model.Controls">
<Design.PreviewWith>
<ProportionalDockControl Width="300" Height="300" />
</Design.PreviewWith>
Expand All @@ -11,13 +12,16 @@
<Setter Property="Template">
<ControlTemplate>
<DockableControl TrackingMode="Visible">
<ItemsControl ItemsSource="{Binding VisibleDockables}">
<ItemsControl ItemsSource="{Binding VisibleDockables}"
x:DataType="dmc:IProportionalDock">
<ItemsControl.Styles>
<Style Selector="ItemsControl > ContentPresenter">
<Setter x:DataType="core:IDock" Property="(ProportionalStackPanel.Proportion)" Value="{Binding Proportion}" />
<Setter x:DataType="core:IDockable"
Property="(ProportionalStackPanel.Proportion)"
Value="{Binding Proportion}" />
<Setter Property="(ProportionalStackPanel.IsCollapsed)">
<Setter.Value>
<MultiBinding Converter="{x:Static BoolConverters.And}" x:DataType="core:IDock">
<MultiBinding Converter="{x:Static BoolConverters.And}" x:DataType="core:IDockable">
<CompiledBinding Path="IsCollapsable" />
<CompiledBinding Path="IsEmpty" />
</MultiBinding>
Expand All @@ -29,6 +33,7 @@
<ItemsPanelTemplate>
<ProportionalStackPanel DockProperties.IsDropArea="True"
Background="Transparent"
x:DataType="dmc:IProportionalDock"
Orientation="{Binding Orientation, Converter={x:Static converters:OrientationConverter.Instance}}" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
Expand Down
8 changes: 4 additions & 4 deletions src/Dock.Avalonia/Controls/RootDockControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
<ToolPinnedControl DockPanel.Dock="Left"
Orientation="Vertical"
Items="{Binding LeftPinnedDockables}"
IsVisible="{Binding !!LeftPinnedDockables.Count}" />
IsVisible="{Binding !!LeftPinnedDockables.Count, FallbackValue={x:False}}" />
<ToolPinnedControl DockPanel.Dock="Right"
Orientation="Vertical"
Items="{Binding RightPinnedDockables}"
IsVisible="{Binding !!RightPinnedDockables.Count}" />
IsVisible="{Binding !!RightPinnedDockables.Count, FallbackValue={x:False}}" />
<ToolPinnedControl DockPanel.Dock="Top"
Orientation="Horizontal"
Items="{Binding TopPinnedDockables}"
IsVisible="{Binding !!TopPinnedDockables.Count}" />
IsVisible="{Binding !!TopPinnedDockables.Count, FallbackValue={x:False}}" />
<ToolPinnedControl DockPanel.Dock="Bottom"
Orientation="Horizontal"
Items="{Binding BottomPinnedDockables}"
IsVisible="{Binding !!BottomPinnedDockables.Count}" />
IsVisible="{Binding !!BottomPinnedDockables.Count, FallbackValue={x:False}}" />
<Panel>
<ContentControl Content="{Binding ActiveDockable}" Name="PART_MainContent" />
<PinnedDockControl />
Expand Down
2 changes: 1 addition & 1 deletion src/Dock.Avalonia/Controls/ToolChromeControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Padding" Value="0" />
<Setter Property="IsPinned" Value="{CompiledBinding ActiveDockable.OriginalOwner, FallbackValue=False, Converter={x:Static ObjectConverters.IsNotNull}}" x:DataType="controls:IToolDock" />
<Setter Property="IsMaximized" Value="{CompiledBinding $parent[HostWindow].WindowState, FallbackValue=False, Converter={x:Static IsMaximizedConverter.Instance}}" />
<Setter Property="IsMaximized" Value="{CompiledBinding $parent[Window].WindowState, FallbackValue=False, Converter={x:Static IsMaximizedConverter.Instance}}" />

<Setter Property="Template">
<ControlTemplate>
Expand Down
6 changes: 0 additions & 6 deletions src/Dock.Model.Avalonia/Controls/TemplateHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,13 @@ internal static class TemplateHelper
{
if (controlRecycling.TryGetValue(content, out var control))
{
#if DEBUG
Console.WriteLine($"[Cached] {content}, {control}");
#endif
return control as Control;
}

control = TemplateContent.Load(content)?.Result;
if (control is not null)
{
controlRecycling.Add(content, control);
#if DEBUG
Console.WriteLine($"[Added] {content}, {control}");
#endif
}

return control as Control;
Expand Down
50 changes: 1 addition & 49 deletions src/Dock.Model.Avalonia/Core/DockBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,7 @@ public abstract class DockBase : DockableBase, IDock
AvaloniaProperty.RegisterDirect<DockBase, IDockable?>(nameof(FocusedDockable), o => o.FocusedDockable, (o, v) => o.FocusedDockable = v);

/// <summary>
/// Defines the <see cref="Proportion"/> property.
/// </summary>
public static readonly DirectProperty<DockBase, double> ProportionProperty =
AvaloniaProperty.RegisterDirect<DockBase, double>(nameof(Proportion), o => o.Proportion, (o, v) => o.Proportion = v, double.NaN);

/// <summary>
/// Defines the <see cref="Proportion"/> property.
/// Defines the <see cref="Dock"/> property.
/// </summary>
public static readonly DirectProperty<DockBase, DockMode> DockProperty =
AvaloniaProperty.RegisterDirect<DockBase, DockMode>(nameof(Dock), o => o.Dock, (o, v) => o.Dock = v);
Expand All @@ -68,24 +62,12 @@ public abstract class DockBase : DockableBase, IDock
public static readonly DirectProperty<DockBase, bool> IsActiveProperty =
AvaloniaProperty.RegisterDirect<DockBase, bool>(nameof(IsActive), o => o.IsActive, (o, v) => o.IsActive = v);

/// <summary>
/// Defines the <see cref="IsEmpty"/> property.
/// </summary>
public static readonly DirectProperty<DockBase, bool> IsEmptyProperty =
AvaloniaProperty.RegisterDirect<DockBase, bool>(nameof(IsEmpty), o => o.IsEmpty, (o, v) => o.IsEmpty = v);

/// <summary>
/// Defines the <see cref="OpenedDockablesCount"/> property.
/// </summary>
public static readonly DirectProperty<DockBase, int> OpenedDockablesCountProperty =
AvaloniaProperty.RegisterDirect<DockBase, int>(nameof(OpenedDockablesCount), o => o.OpenedDockablesCount, (o, v) => o.OpenedDockablesCount = v);

/// <summary>
/// Defines the <see cref="IsCollapsable"/> property.
/// </summary>
public static readonly DirectProperty<DockBase, bool> IsCollapsableProperty =
AvaloniaProperty.RegisterDirect<DockBase, bool>(nameof(IsCollapsable), o => o.IsCollapsable, (o, v) => o.IsCollapsable = v, true);

/// <summary>
/// Defines the <see cref="CanGoBack"/> property.
/// </summary>
Expand All @@ -103,11 +85,8 @@ public abstract class DockBase : DockableBase, IDock
private IDockable? _activeDockable;
private IDockable? _defaultDockable;
private IDockable? _focusedDockable;
private double _proportion = double.NaN;
private DockMode _dock = DockMode.Center;
private bool _isActive;
private bool _isEmpty;
private bool _isCollapsable = true;
private bool _canGoBack;
private bool _canGoForward;
private int _openedDockablesCount;
Expand Down Expand Up @@ -175,15 +154,6 @@ public IDockable? FocusedDockable
}
}

/// <inheritdoc/>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
[JsonPropertyName("Proportion")]
public double Proportion
{
get => _proportion;
set => SetAndRaise(ProportionProperty, ref _proportion, value);
}

/// <inheritdoc/>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
[JsonPropertyName("Dock")]
Expand All @@ -202,15 +172,6 @@ public bool IsActive
set => SetAndRaise(IsActiveProperty, ref _isActive, value);
}

/// <inheritdoc/>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
[JsonPropertyName("IsEmpty")]
public bool IsEmpty
{
get => _isEmpty;
set => SetAndRaise(IsEmptyProperty, ref _isEmpty, value);
}

/// <inheritdoc/>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
[JsonIgnore]
Expand All @@ -220,15 +181,6 @@ public int OpenedDockablesCount
set => SetAndRaise(OpenedDockablesCountProperty, ref _openedDockablesCount, value);
}

/// <inheritdoc/>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
[JsonPropertyName("IsCollapsable")]
public bool IsCollapsable
{
get => _isCollapsable;
set => SetAndRaise(IsCollapsableProperty, ref _isCollapsable, value);
}

/// <inheritdoc/>
[IgnoreDataMember]
[JsonIgnore]
Expand Down
48 changes: 48 additions & 0 deletions src/Dock.Model.Avalonia/Core/DockableBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ public abstract class DockableBase : StyledElement, IDockable
public static readonly DirectProperty<DockableBase, IFactory?> FactoryProperty =
AvaloniaProperty.RegisterDirect<DockableBase, IFactory?>(nameof(Factory), o => o.Factory, (o, v) => o.Factory = v);

/// <summary>
/// Defines the <see cref="IsEmpty"/> property.
/// </summary>
public static readonly DirectProperty<DockableBase, bool> IsEmptyProperty =
AvaloniaProperty.RegisterDirect<DockableBase, bool>(nameof(IsEmpty), o => o.IsEmpty, (o, v) => o.IsEmpty = v);

/// <summary>
/// Defines the <see cref="IsCollapsable"/> property.
/// </summary>
public static readonly DirectProperty<DockableBase, bool> IsCollapsableProperty =
AvaloniaProperty.RegisterDirect<DockableBase, bool>(nameof(IsCollapsable), o => o.IsCollapsable, (o, v) => o.IsCollapsable = v, true);

/// <summary>
/// Defines the <see cref="Proportion"/> property.
/// </summary>
public static readonly DirectProperty<DockBase, double> ProportionProperty =
AvaloniaProperty.RegisterDirect<DockBase, double>(nameof(Proportion), o => o.Proportion, (o, v) => o.Proportion = v, double.NaN);

/// <summary>
/// Defines the <see cref="CanClose"/> property.
/// </summary>
Expand All @@ -85,6 +103,9 @@ public abstract class DockableBase : StyledElement, IDockable
private IDockable? _owner;
private IDockable? _originalOwner;
private IFactory? _factory;
private bool _isEmpty;
private bool _isCollapsable = true;
private double _proportion = double.NaN;
private bool _canClose = true;
private bool _canPin = true;
private bool _canFloat = true;
Expand Down Expand Up @@ -153,6 +174,33 @@ public IFactory? Factory
set => SetAndRaise(FactoryProperty, ref _factory, value);
}

/// <inheritdoc/>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
[JsonPropertyName("IsEmpty")]
public bool IsEmpty
{
get => _isEmpty;
set => SetAndRaise(IsEmptyProperty, ref _isEmpty, value);
}

/// <inheritdoc/>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
[JsonPropertyName("IsCollapsable")]
public bool IsCollapsable
{
get => _isCollapsable;
set => SetAndRaise(IsCollapsableProperty, ref _isCollapsable, value);
}

/// <inheritdoc/>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
[JsonPropertyName("Proportion")]
public double Proportion
{
get => _proportion;
set => SetAndRaise(ProportionProperty, ref _proportion, value);
}

/// <inheritdoc/>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
[JsonPropertyName("CanClose")]
Expand Down
8 changes: 7 additions & 1 deletion src/Dock.Model.Avalonia/Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ public Factory()
public override IList<T> CreateList<T>(params T[] items) => new AvaloniaList<T>(items);

/// <inheritdoc/>
public override IRootDock CreateRootDock() => new RootDock();
public override IRootDock CreateRootDock() => new RootDock
{
LeftPinnedDockables = CreateList<IDockable>(),
RightPinnedDockables = CreateList<IDockable>(),
TopPinnedDockables = CreateList<IDockable>(),
BottomPinnedDockables = CreateList<IDockable>()
};

/// <inheritdoc/>
public override IProportionalDock CreateProportionalDock() => new ProportionalDock();
Expand Down
27 changes: 0 additions & 27 deletions src/Dock.Model.Mvvm/Core/DockBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ public abstract class DockBase : DockableBase, IDock
private IDockable? _activeDockable;
private IDockable? _defaultDockable;
private IDockable? _focusedDockable;
private double _proportion = double.NaN;
private DockMode _dock = DockMode.Center;
private bool _isCollapsable = true;
private int _openedDockablesCount = 0;
private bool _isActive;
private bool _isEmpty;

/// <summary>
/// Initializes new instance of the <see cref="DockBase"/> class.
Expand Down Expand Up @@ -79,14 +76,6 @@ public IDockable? FocusedDockable
}
}

/// <inheritdoc/>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
public double Proportion
{
get => _proportion;
set => SetProperty(ref _proportion, value);
}

/// <inheritdoc/>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
public DockMode Dock
Expand All @@ -103,22 +92,6 @@ public bool IsActive
set => SetProperty(ref _isActive, value);
}

/// <inheritdoc/>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
public bool IsEmpty
{
get => _isEmpty;
set => SetProperty(ref _isEmpty, value);
}

/// <inheritdoc/>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
public bool IsCollapsable
{
get => _isCollapsable;
set => SetProperty(ref _isCollapsable, value);
}

/// <inheritdoc/>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
public int OpenedDockablesCount
Expand Down
27 changes: 27 additions & 0 deletions src/Dock.Model.Mvvm/Core/DockableBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public abstract class DockableBase : ObservableObject, IDockable
private IDockable? _owner;
private IDockable? _originalOwner;
private IFactory? _factory;
private bool _isEmpty;
private bool _isCollapsable = true;
private double _proportion = double.NaN;
private bool _canClose = true;
private bool _canPin = true;
private bool _canFloat = true;
Expand Down Expand Up @@ -78,6 +81,30 @@ public IFactory? Factory
set => SetProperty(ref _factory, value);
}

/// <inheritdoc/>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
public bool IsEmpty
{
get => _isEmpty;
set => SetProperty(ref _isEmpty, value);
}

/// <inheritdoc/>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
public bool IsCollapsable
{
get => _isCollapsable;
set => SetProperty(ref _isCollapsable, value);
}

/// <inheritdoc/>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
public double Proportion
{
get => _proportion;
set => SetProperty(ref _proportion, value);
}

/// <inheritdoc/>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
public bool CanClose
Expand Down
Loading

0 comments on commit 9034af1

Please sign in to comment.