2017-08-22 10:29:00 +02:00
|
|
|
|
/*
|
2019-01-09 11:25:21 +01:00
|
|
|
|
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
|
2017-08-22 10:29:00 +02:00
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
using System.Windows.Markup;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
2019-01-23 15:57:49 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Core;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
|
2019-01-11 15:32:47 +01:00
|
|
|
|
namespace SafeExamBrowser.UserInterface.Desktop.Utilities
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
|
|
|
|
internal static class IconResourceLoader
|
|
|
|
|
{
|
|
|
|
|
internal static UIElement Load(IIconResource resource)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (resource.IsBitmapResource)
|
|
|
|
|
{
|
|
|
|
|
return LoadBitmapResource(resource);
|
|
|
|
|
}
|
|
|
|
|
else if (resource.IsXamlResource)
|
|
|
|
|
{
|
|
|
|
|
return LoadXamlResource(resource);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
2017-08-22 15:47:42 +02:00
|
|
|
|
return NotFoundSymbol();
|
2017-08-22 10:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new NotSupportedException($"Application icon resource of type '{resource.GetType()}' is not supported!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static UIElement LoadBitmapResource(IIconResource resource)
|
|
|
|
|
{
|
|
|
|
|
return new Image
|
|
|
|
|
{
|
|
|
|
|
Source = new BitmapImage(resource.Uri)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static UIElement LoadXamlResource(IIconResource resource)
|
|
|
|
|
{
|
|
|
|
|
using (var stream = Application.GetResourceStream(resource.Uri)?.Stream)
|
|
|
|
|
{
|
|
|
|
|
return XamlReader.Load(stream) as UIElement;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-22 15:47:42 +02:00
|
|
|
|
|
|
|
|
|
private static UIElement NotFoundSymbol()
|
|
|
|
|
{
|
|
|
|
|
return new TextBlock(new Run("X") { Foreground = Brushes.Red, FontWeight = FontWeights.Bold })
|
|
|
|
|
{
|
|
|
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
|
|
VerticalAlignment = VerticalAlignment.Center
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-08-22 10:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|