-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
FormsBitmapIcon.cs
41 lines (35 loc) · 1.12 KB
/
FormsBitmapIcon.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace Xamarin.Forms.Platform.WPF.Controls
{
public class FormsBitmapIcon : FormsElementIcon
{
public static readonly DependencyProperty UriSourceProperty = DependencyProperty.Register("UriSource", typeof(Uri), typeof(FormsBitmapIcon), new PropertyMetadata(OnSourceChanged));
public Uri UriSource
{
get { return (Uri)GetValue(UriSourceProperty); }
set { SetValue(UriSourceProperty, value); }
}
public FormsBitmapIcon()
{
this.DefaultStyleKey = typeof(FormsBitmapIcon);
}
private static void OnSourceChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
((FormsBitmapIcon)o).OnSourceChanged(e.OldValue, e.NewValue);
}
private void OnSourceChanged(object oldValue, object newValue)
{
if (newValue is Uri uri && !uri.IsAbsoluteUri)
{
var name = Assembly.GetEntryAssembly().GetName().Name;
UriSource = new Uri(string.Format("pack://application:,,,/{0};component/{1}", name, uri.OriginalString));
}
}
}
}