Skip to content

Commit 3128bc3

Browse files
authored
Merge pull request #61 from paulushub/master
Fixed Issue #60, added sample
2 parents 6271731 + 485b3ed commit 3128bc3

27 files changed

+1681
-289
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
</configuration>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<Application x:Class="IconConverterSample.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:IconConverterSample"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
<Style x:Key="ScrollBarTrackThumb"
8+
TargetType="{x:Type Thumb}">
9+
<Setter Property="Template">
10+
<Setter.Value>
11+
<ControlTemplate TargetType="{x:Type Thumb}">
12+
<Grid x:Name="Grid">
13+
<Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Fill="Transparent" />
14+
<Border x:Name="CornerScrollBarRectangle" CornerRadius="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
15+
Width="Auto" Height="Auto" Margin="0,1,0,1" Background="{TemplateBinding Background}" />
16+
</Grid>
17+
<ControlTemplate.Triggers>
18+
<Trigger Property="Tag" Value="Horizontal">
19+
<Setter TargetName="CornerScrollBarRectangle" Property="Width" Value="Auto" />
20+
<Setter TargetName="CornerScrollBarRectangle" Property="Height" Value="8" />
21+
</Trigger>
22+
</ControlTemplate.Triggers>
23+
</ControlTemplate>
24+
</Setter.Value>
25+
</Setter>
26+
</Style>
27+
<Style TargetType="{x:Type ScrollBar}">
28+
<Setter Property="Stylus.IsFlicksEnabled" Value="false" />
29+
<Setter Property="Foreground" Value="DeepSkyBlue" />
30+
<Setter Property="Background" Value="Transparent" />
31+
<Setter Property="Width" Value="9" />
32+
<Setter Property="Template">
33+
<Setter.Value>
34+
<ControlTemplate TargetType="{x:Type ScrollBar}">
35+
<Grid x:Name="GridRoot" Width="9" Background="{TemplateBinding Background}">
36+
<Grid.RowDefinitions>
37+
<RowDefinition Height="0.00001*" />
38+
</Grid.RowDefinitions>
39+
<Track x:Name="PART_Track" Grid.Row="0" IsDirectionReversed="true" Focusable="false">
40+
<Track.Thumb>
41+
<Thumb x:Name="Thumb" Background="{TemplateBinding Foreground}" Style="{DynamicResource ScrollBarTrackThumb}" />
42+
</Track.Thumb>
43+
<Track.IncreaseRepeatButton>
44+
<RepeatButton x:Name="PageUp" Command="ScrollBar.PageDownCommand" Opacity="0" Focusable="false" />
45+
</Track.IncreaseRepeatButton>
46+
<Track.DecreaseRepeatButton>
47+
<RepeatButton x:Name="PageDown" Command="ScrollBar.PageUpCommand" Opacity="0" Focusable="false" />
48+
</Track.DecreaseRepeatButton>
49+
</Track>
50+
</Grid>
51+
<ControlTemplate.Triggers>
52+
<Trigger SourceName="Thumb" Property="IsMouseOver" Value="true">
53+
<Setter Value="{DynamicResource ButtonSelectBrush}" TargetName="Thumb" Property="Background" />
54+
</Trigger>
55+
<Trigger SourceName="Thumb" Property="IsDragging" Value="true">
56+
<Setter Value="{DynamicResource DarkBrush}" TargetName="Thumb" Property="Background" />
57+
</Trigger>
58+
59+
<Trigger Property="IsEnabled" Value="false">
60+
<Setter TargetName="Thumb" Property="Visibility" Value="Collapsed" />
61+
</Trigger>
62+
<Trigger Property="Orientation" Value="Horizontal">
63+
<Setter TargetName="GridRoot" Property="LayoutTransform">
64+
<Setter.Value>
65+
<RotateTransform Angle="-90" />
66+
</Setter.Value>
67+
</Setter>
68+
<Setter TargetName="PART_Track" Property="LayoutTransform">
69+
<Setter.Value>
70+
<RotateTransform Angle="-90" />
71+
</Setter.Value>
72+
</Setter>
73+
<Setter Property="Width" Value="Auto" />
74+
<Setter Property="Height" Value="9" />
75+
<Setter TargetName="Thumb" Property="Tag" Value="Horizontal" />
76+
<Setter TargetName="PageDown" Property="Command" Value="ScrollBar.PageLeftCommand" />
77+
<Setter TargetName="PageUp" Property="Command" Value="ScrollBar.PageRightCommand" />
78+
</Trigger>
79+
</ControlTemplate.Triggers>
80+
</ControlTemplate>
81+
</Setter.Value>
82+
</Setter>
83+
</Style>
84+
</Application.Resources>
85+
</Application>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Windows;
3+
4+
namespace IconConverterSample
5+
{
6+
/// <summary>
7+
/// Interaction logic for App.xaml
8+
/// </summary>
9+
public partial class App : Application
10+
{
11+
}
12+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
2+
<PropertyGroup>
3+
<TargetFrameworks>net45;net46;net47;net48;netcoreapp3.1</TargetFrameworks>
4+
<OutputType>WinExe</OutputType>
5+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
6+
<UseWPF>true</UseWPF>
7+
<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
8+
<RootNamespace>IconConverterSample</RootNamespace>
9+
<AssemblyName>IconConverterSample</AssemblyName>
10+
</PropertyGroup>
11+
<PropertyGroup>
12+
<StartupObject>IconConverterSample.App</StartupObject>
13+
</PropertyGroup>
14+
<PropertyGroup>
15+
<ApplicationIcon>IconConverterSample.ico</ApplicationIcon>
16+
</PropertyGroup>
17+
<PropertyGroup>
18+
<DefineConstants Condition=" '$(TargetFramework)' == 'net40' ">$(DefineConstants);DOTNET40;NETFULL</DefineConstants>
19+
<DefineConstants Condition="$(TargetFramework.StartsWith('net45'))">$(DefineConstants);DOTNET45;NETFULL</DefineConstants>
20+
<DefineConstants Condition="$(TargetFramework.StartsWith('net46'))">$(DefineConstants);DOTNET46;NETFULL</DefineConstants>
21+
<DefineConstants Condition="$(TargetFramework.StartsWith('net47'))">$(DefineConstants);DOTNET47;NETFULL</DefineConstants>
22+
<DefineConstants Condition="$(TargetFramework.StartsWith('net48'))">$(DefineConstants);DOTNET48;NETFULL</DefineConstants>
23+
<DefineConstants Condition="$(TargetFramework.StartsWith('netcore'))">$(DefineConstants);NETCORE</DefineConstants>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
26+
<DebugType>full</DebugType>
27+
<DebugSymbols>true</DebugSymbols>
28+
<DefineConstants>DEBUG;TRACE</DefineConstants>
29+
<OutputPath>Output\</OutputPath>
30+
</PropertyGroup>
31+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
32+
<DefineConstants>TRACE</DefineConstants>
33+
<OutputPath>Output\</OutputPath>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<ProjectReference Include="..\..\Source\SVGImage\DotNetProjects.SVGImage.csproj" />
37+
</ItemGroup>
38+
<ItemGroup>
39+
<Resource Include="Resources\Hypocolius.svg" />
40+
</ItemGroup>
41+
<ItemGroup>
42+
<Resource Include="Resources\Binding.svg" />
43+
<Resource Include="Resources\ListView.svg" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<Resource Include="IconConverterSample.ico" />
47+
</ItemGroup>
48+
</Project>
172 KB
Binary file not shown.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31402.337
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IconConverterSample", "IconConverterSample.csproj", "{0BCEE391-4E7B-428B-897B-35DFD0C3EE30}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{0BCEE391-4E7B-428B-897B-35DFD0C3EE30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{0BCEE391-4E7B-428B-897B-35DFD0C3EE30}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{0BCEE391-4E7B-428B-897B-35DFD0C3EE30}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{0BCEE391-4E7B-428B-897B-35DFD0C3EE30}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {D0C6C62C-DB50-4178-AC73-35A08A96C011}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<Window x:Class="IconConverterSample.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:svg1="clr-namespace:SVGImage.SVG;assembly=DotNetProjects.SVGImage"
7+
xmlns:local="clr-namespace:IconConverterSample"
8+
mc:Ignorable="d"
9+
Title="SharpVectors: SvgImageBinding Sample (SvgIconConverter Demo) - C#" Height="720" Width="960"
10+
Background="#444444" WindowStartupLocation="CenterScreen" Icon="IconConverterSample.ico">
11+
<DockPanel LastChildFill="True" Margin="4">
12+
<TabControl TabStripPlacement="Top" FontSize="14" Margin="6" Grid.Row="0" Grid.Column="2" Background="#444444">
13+
<TabControl.Resources>
14+
<Style TargetType="TabItem">
15+
<Setter Property="Template">
16+
<Setter.Value>
17+
<ControlTemplate TargetType="TabItem">
18+
<Border Name="Border" BorderThickness="1,1,1,0" BorderBrush="#444444" CornerRadius="8,0,0,0" Margin="2,2">
19+
<ContentPresenter x:Name="ContentSite"
20+
VerticalAlignment="Center"
21+
HorizontalAlignment="Center"
22+
ContentSource="Header"
23+
Margin="10,4"/>
24+
</Border>
25+
<ControlTemplate.Triggers>
26+
<Trigger Property="IsSelected" Value="True">
27+
<Setter TargetName="Border" Property="Background" Value="DeepSkyBlue" />
28+
</Trigger>
29+
<Trigger Property="IsSelected" Value="False">
30+
<Setter TargetName="Border" Property="Background" Value="#808080" />
31+
</Trigger>
32+
</ControlTemplate.Triggers>
33+
</ControlTemplate>
34+
</Setter.Value>
35+
</Setter>
36+
</Style>
37+
</TabControl.Resources>
38+
<TabItem Name="tabSingle" Background="#444444">
39+
<TabItem.Header>
40+
<StackPanel Orientation="Horizontal" Margin="3">
41+
<Image Source="{Binding Converter={svg1:SvgIconConverter AppName=IconConverterSample}, ConverterParameter=/Resources/Binding.svg, Mode=OneWay}" Width="24" Height="24"/>
42+
<TextBlock Text="Binding Demo" Margin="6,0,0,0" VerticalAlignment="Center" />
43+
</StackPanel>
44+
</TabItem.Header>
45+
<Frame Name="frameSingle" Source="PageSingle.xaml"/>
46+
</TabItem>
47+
48+
<TabItem Name="tabMultiple" Background="#444444">
49+
<TabItem.Header>
50+
<StackPanel Orientation="Horizontal" Margin="3">
51+
<Image Source="{Binding Converter={svg1:SvgIconConverter AppName=IconConverterSample}, ConverterParameter=/Resources/ListView.svg, Mode=OneWay}" Width="24" Height="24"/>
52+
<TextBlock Text="Icon Viewer" Margin="6,0,0,0" VerticalAlignment="Center" />
53+
</StackPanel>
54+
</TabItem.Header>
55+
<Frame Name="frameMultiple" Source="PageMultiple.xaml"/>
56+
</TabItem>
57+
58+
<TabItem Name="tabOther" Background="#444444">
59+
<TabItem.Header>
60+
<StackPanel Orientation="Horizontal" Margin="3">
61+
<Image Source="{Binding Converter={svg1:SvgIconConverter AppName=IconConverterSample}, ConverterParameter=/Resources/ListView.svg, Mode=OneWay}" Width="24" Height="24"/>
62+
<TextBlock Text="Ink Canvas" Margin="6,0,0,0" VerticalAlignment="Center" />
63+
</StackPanel>
64+
</TabItem.Header>
65+
<Frame Name="frameOther" Source="PageOther.xaml"/>
66+
</TabItem>
67+
</TabControl>
68+
</DockPanel>
69+
</Window>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System;
2+
using System.Net;
3+
using System.IO;
4+
using System.Reflection;
5+
using System.IO.Compression;
6+
using System.Windows;
7+
8+
namespace IconConverterSample
9+
{
10+
/// <summary>
11+
/// Interaction logic for MainWindow.xaml
12+
/// </summary>
13+
public partial class MainWindow : Window
14+
{
15+
public MainWindow()
16+
{
17+
InitializeComponent();
18+
19+
this.Loaded += OnWindowLoaded;
20+
}
21+
22+
private void OnWindowLoaded(object sender, RoutedEventArgs e)
23+
{
24+
InitializeProtocol(); //For the web access
25+
26+
// ICons credit: https://github.com/icons8/flat-color-icons
27+
string workingDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
28+
29+
string iconsPath = Path.Combine(workingDir, PageMultiple.IconZipFile);
30+
if (!File.Exists(iconsPath))
31+
{
32+
return;
33+
}
34+
35+
var iconsDir = new DirectoryInfo(Path.Combine(workingDir, PageMultiple.IconFolder));
36+
if (!iconsDir.Exists)
37+
{
38+
iconsDir.Create();
39+
40+
ZipFile.ExtractToDirectory(iconsPath, workingDir);
41+
}
42+
}
43+
44+
45+
public void InitializeProtocol()
46+
{
47+
#if DOTNET40
48+
try
49+
{
50+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
51+
| SecurityProtocolTypes.Tls11 | SecurityProtocolTypes.Tls12;
52+
}
53+
catch
54+
{
55+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
56+
return;
57+
}
58+
#else
59+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
60+
| SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
61+
#endif
62+
}
63+
64+
#if DOTNET40
65+
private static class SecurityProtocolTypes
66+
{
67+
public const SecurityProtocolType Tls12 = (SecurityProtocolType)0x00000C00;
68+
public const SecurityProtocolType Tls11 = (SecurityProtocolType)0x00000300;
69+
public const SecurityProtocolType SystemDefault = (SecurityProtocolType)0;
70+
}
71+
#endif
72+
73+
}
74+
75+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<Page x:Class="IconConverterSample.PageMultiple"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:IconConverterSample"
7+
xmlns:svg1="clr-namespace:SVGImage.SVG;assembly=DotNetProjects.SVGImage"
8+
mc:Ignorable="d"
9+
d:DesignHeight="450" d:DesignWidth="800"
10+
Title="PageMultiple">
11+
<DockPanel LastChildFill="True">
12+
<ListView x:Name="IconView" ItemsSource="{Binding}" HorizontalAlignment="Stretch" VerticalAlignment="Top"
13+
Background="#FF0C0C0C" ScrollViewer.HorizontalScrollBarVisibility="Disabled" VerticalContentAlignment="Center">
14+
<ListView.ItemContainerStyle>
15+
<Style TargetType="{x:Type ListViewItem}">
16+
<Setter Property="Template">
17+
<Setter.Value>
18+
<ControlTemplate TargetType="{x:Type ListViewItem}">
19+
<Border Background="White"
20+
CornerRadius="8"
21+
BorderThickness="6"
22+
x:Name="IconBorder"
23+
Margin="8,4,8,4" >
24+
<ContentPresenter />
25+
</Border>
26+
<ControlTemplate.Triggers>
27+
<Trigger Property="IsSelected" Value="true">
28+
<Setter TargetName="IconBorder" Property="BitmapEffect">
29+
<Setter.Value>
30+
<OuterGlowBitmapEffect GlowSize="10" GlowColor="DeepSkyBlue"/>
31+
</Setter.Value>
32+
</Setter>
33+
<Setter TargetName="IconBorder" Property="BorderBrush" Value="DeepSkyBlue"/>
34+
<Setter TargetName="IconBorder" Property="BorderThickness" Value="6"/>
35+
</Trigger>
36+
</ControlTemplate.Triggers>
37+
</ControlTemplate>
38+
</Setter.Value>
39+
</Setter>
40+
</Style>
41+
</ListView.ItemContainerStyle>
42+
<ItemsControl.ItemsPanel>
43+
<ItemsPanelTemplate>
44+
<WrapPanel Orientation="Horizontal"/>
45+
<!--<UniformGrid HorizontalAlignment="Stretch"/>-->
46+
</ItemsPanelTemplate>
47+
</ItemsControl.ItemsPanel>
48+
<ListView.ItemTemplate>
49+
<DataTemplate>
50+
<StackPanel Margin="8,8,8,8" Orientation="Vertical" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
51+
<Image Source="{Binding Path=ImageUri, Converter={svg1:SvgIconConverter}}" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="Uniform" Width="96" Height="96" />
52+
<TextBlock Text="{Binding ImageTitle}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="96" />
53+
</StackPanel>
54+
</DataTemplate>
55+
</ListView.ItemTemplate>
56+
</ListView>
57+
</DockPanel>
58+
</Page>

0 commit comments

Comments
 (0)