Browse Source

Enable SharpTreeView to use Viewbox as icon container.

pull/1704/head
Siegfried Pammer 6 years ago
parent
commit
f51f20eb35
  1. 1
      SharpTreeView/ICSharpCode.TreeView.csproj
  2. 28
      SharpTreeView/IconDataTemplateSelector.cs
  3. 25
      SharpTreeView/Themes/Generic.xaml

1
SharpTreeView/ICSharpCode.TreeView.csproj

@ -46,6 +46,7 @@ @@ -46,6 +46,7 @@
<Compile Include="EditTextBox.cs" />
<Compile Include="ExtensionMethods.cs" />
<Compile Include="GeneralAdorner.cs" />
<Compile Include="IconDataTemplateSelector.cs" />
<Compile Include="InsertMarker.cs" />
<Compile Include="LinesRenderer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

28
SharpTreeView/IconDataTemplateSelector.cs

@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace ICSharpCode.TreeView
{
class IconDataTemplateSelector : DataTemplateSelector
{
public DataTemplate ImageDataTemplate { get; set; }
public DataTemplate VectorDataTemplate { get; set; }
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
if (item is ImageSource)
return ImageDataTemplate;
if (item is DrawingGroup)
return VectorDataTemplate;
return base.SelectTemplate(item, container);
}
}
}

25
SharpTreeView/Themes/Generic.xaml

@ -250,19 +250,30 @@ @@ -250,19 +250,30 @@
<StackPanel Orientation="Horizontal"
Background="Transparent"
ToolTip="{Binding ToolTip}">
<ContentPresenter Name="icon"
<ContentPresenter Name="icon"
Content="{Binding Icon}"
Width="16"
Height="16"
Margin="0 0 5 1"
VerticalAlignment="Center"
Focusable="False">
<ContentPresenter.ContentTemplate>
<DataTemplate>
<Image Source="{Binding}"/>
</DataTemplate>
</ContentPresenter.ContentTemplate>
</ContentPresenter>
<ContentPresenter.ContentTemplateSelector>
<Default:IconDataTemplateSelector>
<Default:IconDataTemplateSelector.ImageDataTemplate>
<DataTemplate>
<Image Source="{Binding}"/>
</DataTemplate>
</Default:IconDataTemplateSelector.ImageDataTemplate>
<Default:IconDataTemplateSelector.VectorDataTemplate>
<DataTemplate>
<Viewbox Width="16" Height="16">
<Rectangle Width="16" Height="16" Fill="{Binding}" />
</Viewbox>
</DataTemplate>
</Default:IconDataTemplateSelector.VectorDataTemplate>
</Default:IconDataTemplateSelector>
</ContentPresenter.ContentTemplateSelector>
</ContentPresenter>
<Border Name="textContainer"
Background="{TemplateBinding TextBackground}">
<ContentPresenter Content="{Binding Text}"

Loading…
Cancel
Save