Browse Source

Enable SharpTreeView to use Viewbox as icon container.

pull/1704/head
Siegfried Pammer 7 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 @@
<Compile Include="EditTextBox.cs" /> <Compile Include="EditTextBox.cs" />
<Compile Include="ExtensionMethods.cs" /> <Compile Include="ExtensionMethods.cs" />
<Compile Include="GeneralAdorner.cs" /> <Compile Include="GeneralAdorner.cs" />
<Compile Include="IconDataTemplateSelector.cs" />
<Compile Include="InsertMarker.cs" /> <Compile Include="InsertMarker.cs" />
<Compile Include="LinesRenderer.cs" /> <Compile Include="LinesRenderer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

28
SharpTreeView/IconDataTemplateSelector.cs

@ -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 @@
<StackPanel Orientation="Horizontal" <StackPanel Orientation="Horizontal"
Background="Transparent" Background="Transparent"
ToolTip="{Binding ToolTip}"> ToolTip="{Binding ToolTip}">
<ContentPresenter Name="icon" <ContentPresenter Name="icon"
Content="{Binding Icon}" Content="{Binding Icon}"
Width="16" Width="16"
Height="16" Height="16"
Margin="0 0 5 1" Margin="0 0 5 1"
VerticalAlignment="Center" VerticalAlignment="Center"
Focusable="False"> Focusable="False">
<ContentPresenter.ContentTemplate> <ContentPresenter.ContentTemplateSelector>
<DataTemplate> <Default:IconDataTemplateSelector>
<Image Source="{Binding}"/> <Default:IconDataTemplateSelector.ImageDataTemplate>
</DataTemplate> <DataTemplate>
</ContentPresenter.ContentTemplate> <Image Source="{Binding}"/>
</ContentPresenter> </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" <Border Name="textContainer"
Background="{TemplateBinding TextBackground}"> Background="{TemplateBinding TextBackground}">
<ContentPresenter Content="{Binding Text}" <ContentPresenter Content="{Binding Text}"

Loading…
Cancel
Save