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.
- Loading branch information
1 parent
d5f71ee
commit 547020f
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/Uno.UI/Microsoft/UI/Xaml/Controls/ImageIcon/ImageIcon.Properties.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Media; | ||
|
||
namespace Microsoft.UI.Xaml.Controls | ||
{ | ||
public partial class ImageIcon | ||
{ | ||
public ImageSource Source | ||
{ | ||
get => (ImageSource)GetValue(SourceProperty); | ||
set => SetValue(SourceProperty, value); | ||
} | ||
|
||
public static DependencyProperty SourceProperty { get; } = | ||
DependencyProperty.Register(nameof(Source), typeof(ImageSource), typeof(ImageIcon), new PropertyMetadata(null, OnSourcePropertyChanged)); | ||
|
||
|
||
private static void OnSourcePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) | ||
{ | ||
var owner = sender as ImageIcon; | ||
owner?.OnSourcePropertyChanged(args); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Uno.UI/Microsoft/UI/Xaml/Controls/ImageIcon/ImageIcon.Uno.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Media; | ||
|
||
namespace Microsoft.UI.Xaml.Controls | ||
{ | ||
public partial class ImageIcon | ||
{ | ||
private bool _initialized = false; | ||
|
||
private void InitializeVisualTree() | ||
{ | ||
if (!_initialized) | ||
{ | ||
var image = new Image | ||
{ | ||
Stretch = Stretch.Uniform | ||
}; | ||
|
||
var grid = new Grid(); | ||
grid.Children.Add(image); | ||
|
||
AddIconElementView(grid); | ||
} | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/Uno.UI/Microsoft/UI/Xaml/Controls/ImageIcon/ImageIcon.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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#nullable enable | ||
|
||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Media; | ||
|
||
namespace Microsoft.UI.Xaml.Controls | ||
{ | ||
public partial class ImageIcon : IconElement | ||
{ | ||
private Image? m_rootImage = null; | ||
|
||
public ImageIcon() | ||
{ | ||
} | ||
|
||
protected override void OnApplyTemplate() | ||
{ | ||
#if HAS_UNO | ||
// Uno specific: WinUI shares the visual tree initialziation with BitmapIcon | ||
InitializeVisualTree(); | ||
#endif | ||
|
||
if (VisualTreeHelper.GetChild(this, 0) is Grid grid) | ||
{ | ||
var image = (Image)VisualTreeHelper.GetChild(grid, 0); | ||
image.Source = Source; | ||
m_rootImage = image; | ||
} | ||
else | ||
{ | ||
m_rootImage = null; | ||
} | ||
} | ||
|
||
private void OnSourcePropertyChanged(DependencyPropertyChangedEventArgs agrs) | ||
{ | ||
if (m_rootImage is { } image) | ||
{ | ||
image.Source = Source; | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Uno.UI/Microsoft/UI/Xaml/Controls/ImageIcon/ImageIcon.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. --> | ||
<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:ImageIcon"> | ||
</Style> | ||
|
||
</ResourceDictionary> |