forked from unoplatform/uno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update InfoBadge to winui3/release/1.4.2
- Loading branch information
1 parent
1c4a60e
commit 95292c5
Showing
5 changed files
with
296 additions
and
299 deletions.
There are no files selected for viewing
137 changes: 69 additions & 68 deletions
137
src/Uno.UI/Microsoft/UI/Xaml/Controls/InfoBadge/InfoBadge.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,109 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
// MUX reference InfoBadge.cpp, commit 76bd573 | ||
// MUX reference InfoBadge.cpp, tag winui3/release/1.4.2 | ||
|
||
using System; | ||
using Uno.UI.Helpers.WinUI; | ||
using Windows.Foundation; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
|
||
namespace Microsoft.UI.Xaml.Controls | ||
namespace Microsoft.UI.Xaml.Controls; | ||
|
||
/// <summary> | ||
/// Represents a control for indicating notifications, alerts, new content, or to attract focus to an area within an app. | ||
/// </summary> | ||
public partial class InfoBadge : Control | ||
{ | ||
public partial class InfoBadge : Control | ||
//private const string IconPresenterName = "IconPresenter"; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the InfoBadge class. | ||
/// </summary> | ||
public InfoBadge() | ||
{ | ||
//private const string IconPresenterName = "IconPresenter"; | ||
DefaultStyleKey = typeof(InfoBadge); | ||
|
||
public InfoBadge() | ||
{ | ||
DefaultStyleKey = typeof(InfoBadge); | ||
SetValue(TemplateSettingsProperty, new InfoBadgeTemplateSettings()); | ||
SizeChanged += OnSizeChanged; | ||
} | ||
|
||
SetValue(TemplateSettingsProperty, new InfoBadgeTemplateSettings()); | ||
SizeChanged += OnSizeChanged; | ||
} | ||
protected override void OnApplyTemplate() | ||
{ | ||
OnDisplayKindPropertiesChanged(); | ||
} | ||
|
||
protected override void OnApplyTemplate() | ||
protected override Size MeasureOverride(Size availableSize) | ||
{ | ||
var defaultDesiredSize = base.MeasureOverride(availableSize); | ||
if (defaultDesiredSize.Width < defaultDesiredSize.Height) | ||
{ | ||
OnDisplayKindPropertiesChanged(); | ||
return new Size(defaultDesiredSize.Height, defaultDesiredSize.Height); | ||
} | ||
return defaultDesiredSize; | ||
} | ||
|
||
private void OnPropertyChanged(DependencyPropertyChangedEventArgs args) | ||
{ | ||
var property = args.Property; | ||
Control thisAsControl = this; | ||
|
||
protected override Size MeasureOverride(Size availableSize) | ||
if (property == ValueProperty) | ||
{ | ||
var defaultDesiredSize = base.MeasureOverride(availableSize); | ||
if (defaultDesiredSize.Width < defaultDesiredSize.Height) | ||
if (Value < -1) | ||
{ | ||
return new Size(defaultDesiredSize.Height, defaultDesiredSize.Height); | ||
throw new ArgumentOutOfRangeException("Value must be equal to or greater than -1"); | ||
} | ||
return defaultDesiredSize; | ||
} | ||
|
||
private void OnPropertyChanged(DependencyPropertyChangedEventArgs args) | ||
if (property == ValueProperty || property == IconSourceProperty) | ||
{ | ||
var property = args.Property; | ||
Control thisAsControl = this; | ||
|
||
if (property == ValueProperty) | ||
{ | ||
if (Value < -1) | ||
{ | ||
throw new ArgumentOutOfRangeException("Value must be equal to or greater than -1"); | ||
} | ||
} | ||
|
||
if (property == ValueProperty || property == IconSourceProperty) | ||
{ | ||
OnDisplayKindPropertiesChanged(); | ||
} | ||
OnDisplayKindPropertiesChanged(); | ||
} | ||
} | ||
|
||
void OnDisplayKindPropertiesChanged() | ||
void OnDisplayKindPropertiesChanged() | ||
{ | ||
Control thisAsControl = this; | ||
if (Value >= 0) | ||
{ | ||
Control thisAsControl = this; | ||
if (Value >= 0) | ||
{ | ||
VisualStateManager.GoToState(thisAsControl, "Value", true); | ||
} | ||
else if (IconSource is { } iconSource) | ||
VisualStateManager.GoToState(thisAsControl, "Value", true); | ||
} | ||
else if (IconSource is { } iconSource) | ||
{ | ||
TemplateSettings.IconElement = iconSource.CreateIconElement(); | ||
if (iconSource is FontIconSource) | ||
{ | ||
TemplateSettings.IconElement = iconSource.CreateIconElement(); | ||
if (iconSource is FontIconSource) | ||
{ | ||
VisualStateManager.GoToState(thisAsControl, "FontIcon", true); | ||
} | ||
else | ||
{ | ||
VisualStateManager.GoToState(thisAsControl, "Icon", true); | ||
} | ||
VisualStateManager.GoToState(thisAsControl, "FontIcon", true); | ||
} | ||
else | ||
{ | ||
VisualStateManager.GoToState(thisAsControl, "Dot", true); | ||
VisualStateManager.GoToState(thisAsControl, "Icon", true); | ||
} | ||
} | ||
else | ||
{ | ||
VisualStateManager.GoToState(thisAsControl, "Dot", true); | ||
} | ||
} | ||
|
||
private void OnSizeChanged(object sender, Windows.UI.Xaml.SizeChangedEventArgs args) | ||
private void OnSizeChanged(object sender, Windows.UI.Xaml.SizeChangedEventArgs args) | ||
{ | ||
CornerRadius GetCornerRadius() | ||
{ | ||
CornerRadius GetCornerRadius() | ||
var cornerRadiusValue = ActualHeight / 2; | ||
if (ReadLocalValue(CornerRadiusProperty) == DependencyProperty.UnsetValue) | ||
{ | ||
var cornerRadiusValue = ActualHeight / 2; | ||
if (SharedHelpers.IsRS5OrHigher()) | ||
{ | ||
if (ReadLocalValue(CornerRadiusProperty) == DependencyProperty.UnsetValue) | ||
{ | ||
return new CornerRadius(cornerRadiusValue, cornerRadiusValue, cornerRadiusValue, cornerRadiusValue); | ||
} | ||
else | ||
{ | ||
return new CornerRadius(); | ||
} | ||
} | ||
return new CornerRadius(cornerRadiusValue, cornerRadiusValue, cornerRadiusValue, cornerRadiusValue); | ||
} | ||
else | ||
{ | ||
return new CornerRadius(); | ||
} | ||
//return new CornerRadius(cornerRadiusValue, cornerRadiusValue, cornerRadiusValue, cornerRadiusValue); | ||
} | ||
|
||
var value = GetCornerRadius(); | ||
var value = GetCornerRadius(); | ||
|
||
TemplateSettings.InfoBadgeCornerRadius = value; | ||
} | ||
TemplateSettings.InfoBadgeCornerRadius = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 3 additions & 7 deletions
10
src/Uno.UI/Microsoft/UI/Xaml/Controls/InfoBadge/InfoBadge.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. --> | ||
<!-- MUX reference InfoBadge.xaml, commit 76bd573 --> | ||
<ResourceDictionary | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:Microsoft.UI.Xaml.Controls"> | ||
|
||
<Style TargetType="local:InfoBadge" BasedOn="{StaticResource DefaultInfoBadgeStyle}"/> | ||
<!-- MUX reference InfoBadge.xaml, tag winui3/release/1.4.2 --> | ||
<ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="using:Microsoft.UI.Xaml.Controls" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<Style TargetType="controls:InfoBadge" BasedOn="{StaticResource DefaultInfoBadgeStyle}" /> | ||
</ResourceDictionary> |
59 changes: 38 additions & 21 deletions
59
src/Uno.UI/Microsoft/UI/Xaml/Controls/InfoBadge/InfoBadgeTemplateSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,51 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
// MUX reference InfoBadgeTemplateSettings.properties.cpp, commit 76bd573 | ||
// MUX reference InfoBadgeTemplateSettings.properties.cpp, tag winui3/release/1.4.2 | ||
|
||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
|
||
namespace Microsoft.UI.Xaml.Controls | ||
namespace Microsoft.UI.Xaml.Controls; | ||
|
||
/// <summary> | ||
/// Provides calculated values that can be referenced as TemplatedParent sources when defining templates for an InfoBadge. | ||
/// </summary> | ||
public partial class InfoBadgeTemplateSettings : DependencyObject | ||
{ | ||
public partial class InfoBadgeTemplateSettings : DependencyObject | ||
/// <summary> | ||
/// Initializes a new instance of the InfoBadgeTemplateSettings class. | ||
/// </summary> | ||
public InfoBadgeTemplateSettings() | ||
{ | ||
public InfoBadgeTemplateSettings() | ||
{ | ||
} | ||
|
||
public IconElement IconElement | ||
{ | ||
get => (IconElement)GetValue(IconElementProperty); | ||
set => SetValue(IconElementProperty, value); | ||
} | ||
} | ||
|
||
public static DependencyProperty IconElementProperty { get; } = | ||
DependencyProperty.Register(nameof(IconElement), typeof(IconElement), typeof(InfoBadgeTemplateSettings), new FrameworkPropertyMetadata(null)); | ||
/// <summary> | ||
/// Gets or sets the icon element for an InfoBadge. | ||
/// </summary> | ||
public IconElement IconElement | ||
{ | ||
get => (IconElement)GetValue(IconElementProperty); | ||
set => SetValue(IconElementProperty, value); | ||
} | ||
|
||
public CornerRadius InfoBadgeCornerRadius | ||
{ | ||
get => (CornerRadius)GetValue(InfoBadgeCornerRadiusProperty); | ||
set => SetValue(InfoBadgeCornerRadiusProperty, value); | ||
} | ||
/// <summary> | ||
/// Identifies the InfoBadgeTemplateSettings.IconElement dependency property. | ||
/// </summary> | ||
public static DependencyProperty IconElementProperty { get; } = | ||
DependencyProperty.Register(nameof(IconElement), typeof(IconElement), typeof(InfoBadgeTemplateSettings), new FrameworkPropertyMetadata(null)); | ||
|
||
public static DependencyProperty InfoBadgeCornerRadiusProperty { get; } = | ||
DependencyProperty.Register(nameof(InfoBadgeCornerRadius), typeof(CornerRadius), typeof(InfoBadgeTemplateSettings), new FrameworkPropertyMetadata(default(CornerRadius))); | ||
/// <summary> | ||
/// Gets or sets the corner radius for an InfoBadge. | ||
/// </summary> | ||
public CornerRadius InfoBadgeCornerRadius | ||
{ | ||
get => (CornerRadius)GetValue(InfoBadgeCornerRadiusProperty); | ||
set => SetValue(InfoBadgeCornerRadiusProperty, value); | ||
} | ||
|
||
/// <summary> | ||
/// Identifies the InfoBadgeTemplateSettings.InfoBadgeCornerRadius dependency property. | ||
/// </summary> | ||
public static DependencyProperty InfoBadgeCornerRadiusProperty { get; } = | ||
DependencyProperty.Register(nameof(InfoBadgeCornerRadius), typeof(CornerRadius), typeof(InfoBadgeTemplateSettings), new FrameworkPropertyMetadata(default(CornerRadius))); | ||
} |
Oops, something went wrong.