[Core/Win] Add type icon support

Closes #118
This commit is contained in:
Eric Maupin 2018-08-23 16:41:22 -04:00
Родитель 76d63916d2
Коммит 8ff08a5cbb
6 изменённых файлов: 65 добавлений и 4 удалений

Просмотреть файл

@ -3,10 +3,12 @@ using System.Collections;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media.Imaging;
using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Windows
@ -82,6 +84,7 @@ namespace Xamarin.PropertyEditing.Windows
base.OnApplyTemplate ();
this.root = (FrameworkElement) GetTemplateChild ("root");
this.typeIcon = (Image) GetTemplateChild ("typeIcon");
this.items = (ItemsControl) GetTemplateChild ("propertyItems");
this.propertiesPane = (FrameworkElement) GetTemplateChild ("propertiesPane");
this.eventsPane = (FrameworkElement) GetTemplateChild ("eventsPane");
@ -99,6 +102,7 @@ namespace Xamarin.PropertyEditing.Windows
private ItemsControl items;
private ChoiceControl paneSelector;
private FrameworkElement propertiesPane, eventsPane;
private Image typeIcon;
private void OnPaneChanged (object sender, EventArgs e)
{
@ -142,6 +146,28 @@ namespace Xamarin.PropertyEditing.Windows
if (ArrangeMode == PropertyArrangeMode.Name)
OnArrangeModeChanged (ArrangeMode);
UpdateIcon ();
}
private async void UpdateIcon ()
{
if (this.typeIcon == null)
return;
Stream icon = await this.vm.GetIconAsync ();
if (icon == null) {
this.typeIcon.Source = null;
this.typeIcon.Visibility = Visibility.Collapsed;
} else {
var source = new BitmapImage();
source.BeginInit();
source.StreamSource = icon;
source.EndInit();
this.typeIcon.Source = source;
this.typeIcon.Visibility = Visibility.Visible;
}
}
private void OnTargetPlatformChanged ()

Просмотреть файл

@ -112,8 +112,8 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Border Visibility="Collapsed" Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" Height="32" Width="32" Margin="1,6,5,2" Background="{DynamicResource PropertiesPanelIconBackgroundBrush}" VerticalAlignment="Center">
<!-- type icon -->
<Border Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" Margin="1,6,5,2" Background="{DynamicResource PropertiesPanelIconBackgroundBrush}" VerticalAlignment="Center">
<Image Name="typeIcon" Height="32" Width="32" Visibility="Collapsed" />
</Border>
<TextBlock Visibility="{Binding IsObjectNameable, Converter={StaticResource BoolToVisibilityConverter}}" Name="nameLabel" Grid.Row="0" Grid.Column="1" Margin="0,2,0,2" Text="{x:Static prop:Resources.Name}" />

Просмотреть файл

@ -0,0 +1,18 @@
using System.IO;
using System.Threading.Tasks;
namespace Xamarin.PropertyEditing
{
public interface IIconProvider
{
/// <summary>
/// Gets an icon for the given <paramref name="types"/>.
/// </summary>
/// <param name="types">The types to get an icon for.</param>
/// <remarks>
/// The types provided in <paramref name="type"/> may not be the same.
/// If they aren't, you should return a generic icon (VS uses an XML Tag).
/// </remarks>
Task<Stream> GetTypeIconAsync (ITypeInfo[] types);
}
}

Просмотреть файл

@ -63,6 +63,12 @@ namespace Xamarin.PropertyEditing
private set;
}
public IIconProvider IconProvider
{
get;
set;
}
/// <summary>
/// Gets or sets whether the platform supports custom expressions (default false).
/// </summary>

Просмотреть файл

@ -1,6 +1,8 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace Xamarin.PropertyEditing.ViewModels
{
@ -88,6 +90,14 @@ namespace Xamarin.PropertyEditing.ViewModels
SetIsExpanded (ArrangeMode, group, isExpanded);
}
public Task<Stream> GetIconAsync ()
{
if (TargetPlatform.IconProvider == null)
return Task.FromResult<Stream> (null);
return TargetPlatform.IconProvider.GetTypeIconAsync (ObjectEditors.Select (oe => oe.TargetType).ToArray ());
}
protected override void OnAddEditors (IEnumerable<EditorViewModel> editors)
{
IEnumerable<EditorViewModel> props = Properties;

Просмотреть файл

@ -91,6 +91,7 @@
<Compile Include="IProvidePath.cs" />
<Compile Include="IResourceProvider.cs" />
<Compile Include="ISelfConstrainedPropertyInfo.cs" />
<Compile Include="IIconProvider.cs" />
<Compile Include="ITypeInfo.cs" />
<Compile Include="IValidator.cs" />
<Compile Include="KnownProperty.cs" />