Skip to content

Commit 7ddee6f

Browse files
author
ArthurHub
committed
WPF - add sample window
1 parent e378b5b commit 7ddee6f

13 files changed

Lines changed: 163 additions & 31 deletions

Source/Demo/Common/DemoUtils.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,31 @@ public class DemoUtils
2121
{
2222
private const int Iterations = 20;
2323

24+
/// <summary>
25+
/// The HTML text used in sample form for HtmlLabel.
26+
/// </summary>
27+
public static String SampleHtmlLabelText
28+
{
29+
get
30+
{
31+
return "This is an <b>HtmlLabel</b> on transparent background with <span style=\"color: red\">colors</span> and links: " +
32+
"<a href=\"http://htmlrenderer.codeplex.com/\">HTML Renderer</a>";
33+
}
34+
}
35+
36+
/// <summary>
37+
/// The HTML text used in sample form for HtmlPanel.
38+
/// </summary>
39+
public static String SampleHtmlPanelText
40+
{
41+
get
42+
{
43+
return "This is an <b>HtmlPanel</b> with <span style=\"color: red\">colors</span> and links: <a href=\"http://htmlrenderer.codeplex.com/\">HTML Renderer</a>" +
44+
"<div style=\"font-size: 1.2em; padding-top: 10px;\" >If there is more text than the size of the control scrollbars will appear.</div>" +
45+
"<br/>Click me to change my <code>Text</code> property.";
46+
}
47+
}
48+
2449
/// <summary>
2550
/// Handle stylesheet resolve.
2651
/// </summary>

Source/Demo/WPF/DemoWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
<ColumnDefinition Width="Auto"/>
1515
</Grid.ColumnDefinitions>
1616
<ToolBar Grid.Column="0">
17-
<Button IsEnabled="False" ToolBar.OverflowMode="Never">
17+
<Button ToolBar.OverflowMode="Never" Click="OnOpenSampleWindow_click" >
1818
<StackPanel Orientation="Horizontal">
1919
<Image Source="{Binding ConverterParameter=form, Converter={StaticResource Converter}}" Tag="form" MaxHeight="18" Margin="0 0 5 0"/>
20-
<TextBlock Text="Open Sample Form" VerticalAlignment="Center"/>
20+
<TextBlock Text="Open Sample Window" VerticalAlignment="Center"/>
2121
</StackPanel>
2222
</Button>
2323
<Separator/>

Source/Demo/WPF/DemoWindow.xaml.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ private static void LoadCustomFonts()
6060
}
6161
}
6262

63+
/// <summary>
64+
/// Open sample window.
65+
/// </summary>
66+
private void OnOpenSampleWindow_click(object sender, RoutedEventArgs e)
67+
{
68+
var w = new SampleWindow();
69+
w.Owner = this;
70+
w.Width = Width * 0.8;
71+
w.Height = Height * 0.8;
72+
w.ShowDialog();
73+
}
74+
6375
/// <summary>
6476
/// Toggle if to show split view of HtmlPanel and WinForms WebBrowser control.
6577
/// </summary>

Source/Demo/WPF/HtmlRenderer.Demo.WPF.csproj

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
1515
<WarningLevel>4</WarningLevel>
1616
<TargetFrameworkProfile />
17+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
18+
<RestorePackages>true</RestorePackages>
1719
</PropertyGroup>
1820
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1921
<PlatformTarget>x86</PlatformTarget>
@@ -45,6 +47,12 @@
4547
<Reference Include="WindowsBase" />
4648
<Reference Include="PresentationCore" />
4749
<Reference Include="PresentationFramework" />
50+
<Reference Include="Xceed.Wpf.DataGrid">
51+
<HintPath>..\..\packages\Extended.Wpf.Toolkit.2.2.1\lib\net40\Xceed.Wpf.DataGrid.dll</HintPath>
52+
</Reference>
53+
<Reference Include="Xceed.Wpf.Toolkit">
54+
<HintPath>..\..\packages\Extended.Wpf.Toolkit.2.2.1\lib\net40\Xceed.Wpf.Toolkit.dll</HintPath>
55+
</Reference>
4856
</ItemGroup>
4957
<ItemGroup>
5058
<ApplicationDefinition Include="App.xaml">
@@ -54,6 +62,9 @@
5462
<Compile Include="GenerateImageWindow.xaml.cs">
5563
<DependentUpon>GenerateImageWindow.xaml</DependentUpon>
5664
</Compile>
65+
<Compile Include="SampleWindow.xaml.cs">
66+
<DependentUpon>SampleWindow.xaml</DependentUpon>
67+
</Compile>
5768
<Compile Include="ToolStripImageConverter.cs" />
5869
<Page Include="DemoWindow.xaml">
5970
<Generator>MSBuild:Compile</Generator>
@@ -75,6 +86,10 @@
7586
<SubType>Designer</SubType>
7687
<Generator>MSBuild:Compile</Generator>
7788
</Page>
89+
<Page Include="SampleWindow.xaml">
90+
<SubType>Designer</SubType>
91+
<Generator>MSBuild:Compile</Generator>
92+
</Page>
7893
</ItemGroup>
7994
<ItemGroup>
8095
<Compile Include="HtmlRenderingHelper.cs" />
@@ -106,6 +121,9 @@
106121
<ItemGroup>
107122
<Resource Include="fonts\CustomFont.ttf" />
108123
</ItemGroup>
124+
<ItemGroup>
125+
<None Include="packages.config" />
126+
</ItemGroup>
109127
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
110128
<Target Name="AfterResolveReferences">
111129
<ItemGroup>
@@ -114,6 +132,13 @@
114132
</EmbeddedResource>
115133
</ItemGroup>
116134
</Target>
135+
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
136+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
137+
<PropertyGroup>
138+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
139+
</PropertyGroup>
140+
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
141+
</Target>
117142
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
118143
Other similar extension points exist, see Microsoft.Common.targets.
119144
<Target Name="BeforeBuild">

Source/Demo/WPF/MainControl.xaml.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ private static void OnRenderError(object sender, HtmlRenderErrorEventArgs e)
314314
/// <summary>
315315
/// On specific link click handle it here.
316316
/// </summary>
317-
private static void OnLinkClicked(object sender, HtmlLinkClickedEventArgs e)
317+
private void OnLinkClicked(object sender, HtmlLinkClickedEventArgs e)
318318
{
319319
if (e.Link == "SayHello")
320320
{
@@ -323,11 +323,16 @@ private static void OnLinkClicked(object sender, HtmlLinkClickedEventArgs e)
323323
}
324324
else if (e.Link == "ShowSampleForm")
325325
{
326-
// using (var f = new SampleForm())
327-
// {
328-
// f.ShowDialog();
329-
// e.Handled = true;
330-
// }
326+
var w = new SampleWindow();
327+
var window = Window.GetWindow(this);
328+
if (window != null)
329+
{
330+
w.Owner = window;
331+
w.Width = window.Width * 0.8;
332+
w.Height = window.Height * 0.8;
333+
w.ShowDialog();
334+
}
335+
e.Handled = true;
331336
}
332337
}
333338

Source/Demo/WPF/SampleWindow.xaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Window x:Class="HtmlRenderer.Demo.WPF.SampleWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
5+
xmlns:wpf="clr-namespace:HtmlRenderer.WPF;assembly=HtmlRenderer.WPF"
6+
Title="Sample Window" Height="300" Width="500" WindowStartupLocation="CenterOwner">
7+
<Grid Background="{x:Static SystemColors.ControlBrush}">
8+
<Grid.ColumnDefinitions>
9+
<ColumnDefinition Width="6*"/>
10+
<ColumnDefinition Width="Auto"/>
11+
<ColumnDefinition Width="4*"/>
12+
</Grid.ColumnDefinitions>
13+
<Grid.RowDefinitions>
14+
<RowDefinition Height="Auto"/>
15+
<RowDefinition/>
16+
<RowDefinition Height="Auto"/>
17+
<RowDefinition/>
18+
</Grid.RowDefinitions>
19+
<TextBlock Text="Html Label" Margin="10 0"/>
20+
<Border Background="{StaticResource TransBackBrush}" Grid.Row="1" Grid.Column="0" Margin="10 5">
21+
<wpf:HtmlLabel x:Name="_htmlLabel" MouseDown="OnHtmlControl_mouseDown" Margin="8" />
22+
</Border>
23+
<TextBlock Text="Html Panel" Grid.Row="2" Grid.Column="0" Margin="10 0"/>
24+
<wpf:HtmlPanel x:Name="_htmlPanel" Grid.Row="3" Grid.Column="0" Margin="10 5" MouseDown="OnHtmlControl_mouseDown"/>
25+
<xctk:PropertyGrid x:Name="_propertyGrid" Grid.Row="0" Grid.Column="2" Grid.RowSpan="5"/>
26+
<GridSplitter Grid.Row="0" Grid.Column="1" Grid.RowSpan="5" Width="4" Background="#BFDBFF" ResizeBehavior="PreviousAndNext" VerticalAlignment="Stretch" />
27+
</Grid>
28+
</Window>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// "Therefore those skilled at the unorthodox
2+
// are infinite as heaven and earth,
3+
// inexhaustible as the great rivers.
4+
// When they come to an end,
5+
// they begin again,
6+
// like the days and months;
7+
// they die and are reborn,
8+
// like the four seasons."
9+
//
10+
// - Sun Tsu,
11+
// "The Art of War"
12+
13+
using System.Windows.Input;
14+
using HtmlRenderer.Demo.Common;
15+
16+
namespace HtmlRenderer.Demo.WPF
17+
{
18+
/// <summary>
19+
/// Interaction logic for SampleWindow.xaml
20+
/// </summary>
21+
public partial class SampleWindow
22+
{
23+
public SampleWindow()
24+
{
25+
InitializeComponent();
26+
27+
_htmlLabel.Html = DemoUtils.SampleHtmlLabelText;
28+
_htmlPanel.Html = DemoUtils.SampleHtmlPanelText;
29+
30+
_propertyGrid.SelectedObject = _htmlLabel;
31+
}
32+
33+
private void OnHtmlControl_mouseDown(object sender, MouseButtonEventArgs e)
34+
{
35+
_propertyGrid.SelectedObject = sender;
36+
}
37+
}
38+
}

Source/Demo/WPF/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Extended.Wpf.Toolkit" version="2.2.1" targetFramework="net40" />
4+
</packages>

Source/Demo/WinForms/SampleForm.Designer.cs

Lines changed: 6 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/Demo/WinForms/SampleForm.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.Drawing;
1515
using System.Drawing.Drawing2D;
1616
using System.Windows.Forms;
17+
using HtmlRenderer.Demo.Common;
1718

1819
namespace HtmlRenderer.Demo.WinForms
1920
{
@@ -27,6 +28,9 @@ public SampleForm()
2728

2829
Icon = DemoForm.GetIcon();
2930

31+
_htmlLabel.Text = DemoUtils.SampleHtmlLabelText;
32+
_htmlPanel.Text = DemoUtils.SampleHtmlPanelText;
33+
3034
_background = HtmlRenderingHelper.CreateImageForTransparentBackground();
3135
}
3236

0 commit comments

Comments
 (0)