Skip to content

Commit 8e4e68c

Browse files
authored
Merge pull request #27 from paulushub/master
Adding two markup extension classes from the SharpVectors project
2 parents e841590 + d01e91d commit 8e4e68c

File tree

14 files changed

+1735
-22
lines changed

14 files changed

+1735
-22
lines changed

Samples/ClipArtViewer/MainWindow.xaml.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,24 @@ public List<SVGItem> Items
5656
get { return m_items; }
5757
}
5858

59+
private bool _isShown;
60+
5961
public MainWindow()
6062
{
6163
InitializeComponent();
6264

6365
this.Loaded += OnMainWindowLoaded;
6466
}
6567

66-
private void OnMainWindowLoaded(object sender, RoutedEventArgs e)
68+
protected override void OnContentRendered(EventArgs e)
6769
{
68-
txtLogger.Document.Blocks.Clear();
69-
txtLogger.SetValue(Block.LineHeightProperty, 1.0);
70-
Trace.Listeners.Add(new TextBoxTraceListener(txtLogger));
70+
base.OnContentRendered(e);
71+
72+
if (_isShown)
73+
{
74+
return;
75+
}
76+
_isShown = true;
7177

7278
// default path
7379
string appPath = Process.GetCurrentProcess().MainModule.FileName;
@@ -85,6 +91,13 @@ private void OnMainWindowLoaded(object sender, RoutedEventArgs e)
8591
tabPages.SelectedIndex = 0;
8692
}
8793

94+
private void OnMainWindowLoaded(object sender, RoutedEventArgs e)
95+
{
96+
txtLogger.Document.Blocks.Clear();
97+
txtLogger.SetValue(Block.LineHeightProperty, 1.0);
98+
Trace.Listeners.Add(new TextBoxTraceListener(txtLogger));
99+
}
100+
88101
void ListFiles()
89102
{
90103
string path = this.SvgPath;

Samples/Example/App.xaml

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,82 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
StartupUri="MainWindow.xaml">
55
<Application.Resources>
6-
6+
<Style x:Key="ScrollBarTrackThumb"
7+
TargetType="{x:Type Thumb}">
8+
<Setter Property="Template">
9+
<Setter.Value>
10+
<ControlTemplate TargetType="{x:Type Thumb}">
11+
<Grid x:Name="Grid">
12+
<Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Fill="Transparent" />
13+
<Border x:Name="CornerScrollBarRectangle" CornerRadius="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
14+
Width="Auto" Height="Auto" Margin="0,1,0,1" Background="{TemplateBinding Background}" />
15+
</Grid>
16+
<ControlTemplate.Triggers>
17+
<Trigger Property="Tag" Value="Horizontal">
18+
<Setter TargetName="CornerScrollBarRectangle" Property="Width" Value="Auto" />
19+
<Setter TargetName="CornerScrollBarRectangle" Property="Height" Value="8" />
20+
</Trigger>
21+
</ControlTemplate.Triggers>
22+
</ControlTemplate>
23+
</Setter.Value>
24+
</Setter>
25+
</Style>
26+
<Style TargetType="{x:Type ScrollBar}">
27+
<Setter Property="Stylus.IsFlicksEnabled" Value="false" />
28+
<Setter Property="Foreground" Value="DeepSkyBlue" />
29+
<Setter Property="Background" Value="Transparent" />
30+
<Setter Property="Width" Value="9" />
31+
<Setter Property="Template">
32+
<Setter.Value>
33+
<ControlTemplate TargetType="{x:Type ScrollBar}">
34+
<Grid x:Name="GridRoot" Width="9" Background="{TemplateBinding Background}">
35+
<Grid.RowDefinitions>
36+
<RowDefinition Height="0.00001*" />
37+
</Grid.RowDefinitions>
38+
<Track x:Name="PART_Track" Grid.Row="0" IsDirectionReversed="true" Focusable="false">
39+
<Track.Thumb>
40+
<Thumb x:Name="Thumb" Background="{TemplateBinding Foreground}" Style="{DynamicResource ScrollBarTrackThumb}" />
41+
</Track.Thumb>
42+
<Track.IncreaseRepeatButton>
43+
<RepeatButton x:Name="PageUp" Command="ScrollBar.PageDownCommand" Opacity="0" Focusable="false" />
44+
</Track.IncreaseRepeatButton>
45+
<Track.DecreaseRepeatButton>
46+
<RepeatButton x:Name="PageDown" Command="ScrollBar.PageUpCommand" Opacity="0" Focusable="false" />
47+
</Track.DecreaseRepeatButton>
48+
</Track>
49+
</Grid>
50+
<ControlTemplate.Triggers>
51+
<Trigger SourceName="Thumb" Property="IsMouseOver" Value="true">
52+
<Setter Value="{DynamicResource ButtonSelectBrush}" TargetName="Thumb" Property="Background" />
53+
</Trigger>
54+
<Trigger SourceName="Thumb" Property="IsDragging" Value="true">
55+
<Setter Value="{DynamicResource DarkBrush}" TargetName="Thumb" Property="Background" />
56+
</Trigger>
57+
58+
<Trigger Property="IsEnabled" Value="false">
59+
<Setter TargetName="Thumb" Property="Visibility" Value="Collapsed" />
60+
</Trigger>
61+
<Trigger Property="Orientation" Value="Horizontal">
62+
<Setter TargetName="GridRoot" Property="LayoutTransform">
63+
<Setter.Value>
64+
<RotateTransform Angle="-90" />
65+
</Setter.Value>
66+
</Setter>
67+
<Setter TargetName="PART_Track" Property="LayoutTransform">
68+
<Setter.Value>
69+
<RotateTransform Angle="-90" />
70+
</Setter.Value>
71+
</Setter>
72+
<Setter Property="Width" Value="Auto" />
73+
<Setter Property="Height" Value="9" />
74+
<Setter TargetName="Thumb" Property="Tag" Value="Horizontal" />
75+
<Setter TargetName="PageDown" Property="Command" Value="ScrollBar.PageLeftCommand" />
76+
<Setter TargetName="PageUp" Property="Command" Value="ScrollBar.PageRightCommand" />
77+
</Trigger>
78+
</ControlTemplate.Triggers>
79+
</ControlTemplate>
80+
</Setter.Value>
81+
</Setter>
82+
</Style>
783
</Application.Resources>
884
</Application>

Samples/Example/Example.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
<PropertyGroup>
2222
<ApplicationIcon>Example.ico</ApplicationIcon>
2323
</PropertyGroup>
24+
<PropertyGroup>
25+
<DefineConstants Condition=" '$(TargetFramework)' == 'net40' ">$(DefineConstants);DOTNET40;NETFULL</DefineConstants>
26+
<DefineConstants Condition="$(TargetFramework.StartsWith('net45'))">$(DefineConstants);DOTNET45;NETFULL</DefineConstants>
27+
<DefineConstants Condition="$(TargetFramework.StartsWith('net46'))">$(DefineConstants);DOTNET46;NETFULL</DefineConstants>
28+
<DefineConstants Condition="$(TargetFramework.StartsWith('net47'))">$(DefineConstants);DOTNET47;NETFULL</DefineConstants>
29+
<DefineConstants Condition="$(TargetFramework.StartsWith('net48'))">$(DefineConstants);DOTNET48;NETFULL</DefineConstants>
30+
<DefineConstants Condition="$(TargetFramework.StartsWith('netcore'))">$(DefineConstants);NETCORE</DefineConstants>
31+
</PropertyGroup>
2432
<ItemGroup>
2533
<ProjectReference Include="..\..\Source\SVGImage\DotNetProjects.SVGImage.csproj" />
2634
</ItemGroup>
@@ -48,6 +56,10 @@
4856
<Resource Include="Images\Human_body_proportions2_svg.svg" />
4957
<Resource Include="Images\example8.1.test01.svg" />
5058
</ItemGroup>
59+
<ItemGroup>
60+
<Resource Include="Resources\alphachannel.svg" />
61+
<Resource Include="Resources\television_comic.svg" />
62+
</ItemGroup>
5163
<ItemGroup>
5264
<None Include="raupen.jpg">
5365
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

Samples/Example/MainWindow.xaml

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,59 @@
139139
<TabItem Header="SVG Icons" Height="40" Width="245" x:Name="tabIcons" Style="{DynamicResource TabItem.Style.TopTabStripPlacement}">
140140
<Grid Background="Wheat" ShowGridLines="True">
141141
<Grid.RowDefinitions>
142-
<RowDefinition/>
143-
<RowDefinition/>
142+
<RowDefinition Height="1*"/>
143+
<RowDefinition Height="3*"/>
144144
</Grid.RowDefinitions>
145+
<UniformGrid Grid.Row="0" Columns="3" Rows="1" Margin="15">
146+
<Image Source="{svg1:SvgIcon Source=/Resources/alphachannel.svg, AppName=Example}" Stretch="Uniform"/>
147+
<Image Source="{svg1:SvgIcon Source=/Resources/television_comic.svg, AppName=Example}" Stretch="Uniform"/>
148+
<Image Source="{svg1:SvgIcon Source=/Images/tombigel_green_router.svg, AppName=Example}" Stretch="Uniform"/>
149+
</UniformGrid>
150+
<ListView Grid.Row="1" Margin="15" x:Name="IconView" ItemsSource="{Binding}" HorizontalAlignment="Stretch" VerticalAlignment="Top"
151+
Background="PaleGoldenrod" ScrollViewer.HorizontalScrollBarVisibility="Disabled" VerticalContentAlignment="Center">
152+
<ListView.ItemContainerStyle>
153+
<Style TargetType="{x:Type ListViewItem}">
154+
<Setter Property="Template">
155+
<Setter.Value>
156+
<ControlTemplate TargetType="{x:Type ListViewItem}">
157+
<Border Background="White"
158+
CornerRadius="8"
159+
BorderThickness="6"
160+
x:Name="IconBorder"
161+
Margin="8,4,8,4" >
162+
<ContentPresenter />
163+
</Border>
164+
<ControlTemplate.Triggers>
165+
<Trigger Property="IsSelected" Value="true">
166+
<Setter TargetName="IconBorder" Property="BitmapEffect">
167+
<Setter.Value>
168+
<OuterGlowBitmapEffect GlowSize="10" GlowColor="DeepSkyBlue"/>
169+
</Setter.Value>
170+
</Setter>
171+
<Setter TargetName="IconBorder" Property="BorderBrush" Value="DeepSkyBlue"/>
172+
<Setter TargetName="IconBorder" Property="BorderThickness" Value="6"/>
173+
</Trigger>
174+
</ControlTemplate.Triggers>
175+
</ControlTemplate>
176+
</Setter.Value>
177+
</Setter>
178+
</Style>
179+
</ListView.ItemContainerStyle>
180+
<ItemsControl.ItemsPanel>
181+
<ItemsPanelTemplate>
182+
<WrapPanel Orientation="Horizontal"/>
183+
<!--<UniformGrid HorizontalAlignment="Stretch"/>-->
184+
</ItemsPanelTemplate>
185+
</ItemsControl.ItemsPanel>
186+
<ListView.ItemTemplate>
187+
<DataTemplate>
188+
<StackPanel Margin="8,8,8,8" Orientation="Vertical" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
189+
<Image Source="{Binding Path=ImageUri, Converter={svg1:SvgIconConverter}}" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="Uniform" Width="96" Height="96" />
190+
<TextBlock Text="{Binding ImageTitle}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="96" />
191+
</StackPanel>
192+
</DataTemplate>
193+
</ListView.ItemTemplate>
194+
</ListView>
145195
</Grid>
146196
</TabItem>
147197
</TabControl>

Samples/Example/MainWindow.xaml.cs

Lines changed: 126 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,143 @@
11
using System;
2+
using System.IO;
3+
using System.IO.Compression;
24
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5+
56
using System.Windows;
6-
using System.Windows.Controls;
7-
using System.Windows.Data;
8-
using System.Windows.Documents;
9-
using System.Windows.Input;
10-
using System.Windows.Media;
11-
using System.Windows.Media.Imaging;
12-
using System.Windows.Navigation;
13-
using System.Windows.Shapes;
147

158
namespace Example
169
{
10+
public class IconData
11+
{
12+
private Uri _uri;
13+
private string _title;
14+
15+
public IconData()
16+
{
17+
}
18+
19+
public IconData(FileInfo source)
20+
{
21+
if (source != null)
22+
{
23+
_title = Path.GetFileNameWithoutExtension(source.Name);
24+
_uri = new Uri(source.FullName);
25+
}
26+
}
27+
28+
public string ImageTitle
29+
{
30+
get { return _title; }
31+
set { _title = value; }
32+
}
33+
34+
public Uri ImageUri
35+
{
36+
get { return _uri; }
37+
set { _uri = value; }
38+
}
39+
}
40+
1741
/// <summary>
1842
/// Interaction logic for MainWindow.xaml
1943
/// </summary>
2044
public partial class MainWindow : Window
2145
{
46+
private const string SamplesDir = @"..\..\..\..\..\Tests";
47+
private const string IconZipFile = "svg-icons.zip";
48+
private const string IconFolder = "Svg-Icons";
49+
50+
private bool _isShown;
51+
private bool _showMessage;
52+
private string _iconsPath;
53+
2254
public MainWindow()
2355
{
2456
InitializeComponent();
57+
58+
this.Loaded += OnMainWindowLoaded;
59+
}
60+
61+
protected override void OnContentRendered(EventArgs e)
62+
{
63+
base.OnContentRendered(e);
64+
65+
if (_isShown)
66+
{
67+
return;
68+
}
69+
_isShown = true;
70+
71+
if (_showMessage && !string.IsNullOrWhiteSpace(_iconsPath))
72+
{
73+
_showMessage = false;
74+
MessageBox.Show("For the .NET 4.0 build, the grid of icons may not be shown at bottom panel of the SVG Icons." +
75+
"\nIn this case, manually extract the following zip file and restart this sample application." +
76+
"\n\n" + _iconsPath, "SVG Icons Tab", MessageBoxButton.OK, MessageBoxImage.Information);
77+
}
78+
}
79+
80+
private void OnMainWindowLoaded(object sender, RoutedEventArgs e)
81+
{
82+
this.EnsureIcons();
83+
84+
string workingDir = Path.GetFullPath(SamplesDir);
85+
86+
string iconsPath = Path.Combine(workingDir, IconZipFile);
87+
if (!File.Exists(iconsPath))
88+
{
89+
return;
90+
}
91+
92+
var iconsDir = new DirectoryInfo(Path.Combine(workingDir, IconFolder));
93+
if (!iconsDir.Exists)
94+
{
95+
return;
96+
}
97+
98+
FileInfo[] iconFiles = iconsDir.GetFiles("*.svg", SearchOption.TopDirectoryOnly);
99+
if (iconFiles == null || iconFiles.Length == 0)
100+
{
101+
return;
102+
}
103+
104+
List<IconData> sourceData = new List<IconData>(iconFiles.Length);
105+
foreach (var iconFile in iconFiles)
106+
{
107+
sourceData.Add(new IconData(iconFile));
108+
}
109+
// sourceData.Add(new IconData()); //Test-Empty
110+
111+
this.DataContext = sourceData;
112+
}
113+
114+
private void EnsureIcons()
115+
{
116+
// Icons credit: https://github.com/icons8/flat-color-icons
117+
string workingDir = Path.GetFullPath(SamplesDir);
118+
119+
string iconsPath = Path.Combine(workingDir, IconZipFile);
120+
if (!File.Exists(iconsPath))
121+
{
122+
return;
123+
}
124+
var iconsDir = new DirectoryInfo(Path.Combine(workingDir, IconFolder));
125+
126+
_iconsPath = iconsPath;
127+
128+
#if !DOTNET40
129+
if (!iconsDir.Exists)
130+
{
131+
iconsDir.Create();
132+
133+
ZipFile.ExtractToDirectory(iconsPath, workingDir);
134+
}
135+
#else
136+
if (!iconsDir.Exists)
137+
{
138+
_showMessage = true;
139+
}
140+
#endif
25141
}
26142
}
27143
}
Lines changed: 5 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)