mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
source code checkin
This commit is contained in:
parent
5f8fb2c825
commit
7e57b72e35
675 changed files with 168433 additions and 0 deletions
47
src/Plugin.Common/Extensions/IconExtension.cs
Normal file
47
src/Plugin.Common/Extensions/IconExtension.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows.Markup;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace ServerManagerTool.Plugin.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple extension for icon, to let you choose icon with specific size.
|
||||
/// Usage sample:
|
||||
/// Image Stretch="None" Source="{common:Icon /Controls;component/icons/custom.ico, 16}"
|
||||
/// Or:
|
||||
/// Image Source="{common:Icon Source={Binding IconResource}, Size=16}"
|
||||
/// </summary>
|
||||
public class IconExtension : MarkupExtension
|
||||
{
|
||||
private string _path;
|
||||
|
||||
public string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
set
|
||||
{
|
||||
// Have to make full pack URI from short form, so System.Uri recognizes it.
|
||||
_path = $"pack://application:,,,{value}";
|
||||
}
|
||||
}
|
||||
|
||||
public int Size { get; set; }
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
{
|
||||
var decoder = BitmapDecoder.Create(new Uri(Path), BitmapCreateOptions.DelayCreation, BitmapCacheOption.OnDemand);
|
||||
|
||||
var result = decoder.Frames.SingleOrDefault(f => f.Width == Size);
|
||||
if (result == default(BitmapFrame))
|
||||
{
|
||||
result = decoder.Frames.OrderBy(f => f.Width).First();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue