Skip to content

Commit 51f36c1

Browse files
committed
Added SourceRouter class
- to easify the process of switching the source from local to remote
1 parent 6ac6163 commit 51f36c1

File tree

8 files changed

+54
-56
lines changed

8 files changed

+54
-56
lines changed

MainDemo.Wpf/.Buttons.xaml.swp

24 KB
Binary file not shown.

MainDemo.Wpf/Buttons.xaml.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Xml;
1717
using CodeDisplayer;
1818
using MaterialDesignColors.WpfExample.Domain;
19+
using MaterialDesignDemo.Helper;
1920

2021
namespace MaterialDesignColors.WpfExample
2122
{
@@ -27,14 +28,9 @@ public partial class Buttons : UserControl
2728
public Buttons()
2829
{
2930
InitializeComponent();
30-
3131
FloatingActionDemoCommand = new AnotherCommandImplementation(Execute);
32-
var xmlDoc = new XmlDocument();
33-
string source = File.ReadAllText(@"..\..\Buttons.xaml");
34-
xmlDoc.LoadXml(source);
35-
XamlDisplayerPanel.Initialize(xmlDoc);
36-
//XamlDisplayerPanel.Initialize(new MaterialDesignInXamlToolkitGitHubFile(this.GetType().Name).GetXmlDocument());
37-
}
32+
XamlDisplayerPanel.Initialize(new SourceRouter(this.GetType().Name).GetSource());
33+
}
3834

3935
public ICommand FloatingActionDemoCommand { get; }
4036

MainDemo.Wpf/Cards.xaml.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System.Windows.Shapes;
1616
using System.Xml;
1717
using CodeDisplayer;
18+
using MaterialDesignDemo.Helper;
1819

1920
namespace MaterialDesignColors.WpfExample
2021
{
@@ -25,17 +26,8 @@ public partial class Cards : UserControl
2526
{
2627
public Cards()
2728
{
28-
InitializeComponent();
29-
//var xmlDoc = new XmlDocument();
30-
//string source = File.ReadAllText(@"..\..\Cards.xaml");
31-
//xmlDoc.LoadXml(source);
32-
XmlDocument xmlDoc =
33-
new MaterialDesignInXamlToolkitGitHubFile(
34-
ownerName: "wongjiahau" ,
35-
branchName: "New-Demo-2" ,
36-
fileName: "Cards.xaml")
37-
.GetXmlDocument();
38-
XamlDisplayerPanel.Initialize(xmlDoc);
29+
InitializeComponent();
30+
XamlDisplayerPanel.Initialize(new SourceRouter(this.GetType().Name).GetSource());
3931
}
4032

4133

MainDemo.Wpf/Chips.xaml.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using System.Windows.Navigation;
1414
using System.Windows.Shapes;
1515
using System.Xml;
16+
using MaterialDesignDemo.Helper;
1617

1718
namespace MaterialDesignColors.WpfExample
1819
{
@@ -24,10 +25,7 @@ public partial class Chips : UserControl
2425
public Chips()
2526
{
2627
InitializeComponent();
27-
var xmlDoc = new XmlDocument();
28-
xmlDoc.Load(@"C:\Users\User\Desktop\MaterialDesignXAMLToolKitNew\MaterialDesignInXamlToolkit\MainDemo.Wpf\Chips.xaml");
29-
this.XamlDisplayerPanel.Initialize(xmlDoc); ;
30-
28+
XamlDisplayerPanel.Initialize(new SourceRouter(this.GetType().Name).GetSource());
3129
}
3230

3331
private void ButtonsDemoChip_OnClick(object sender, RoutedEventArgs e)

MainDemo.Wpf/Drawers.xaml.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using System.Windows.Navigation;
1414
using System.Windows.Shapes;
1515
using System.Xml;
16+
using MaterialDesignDemo.Helper;
1617

1718
namespace MaterialDesignDemo
1819
{
@@ -24,9 +25,7 @@ public partial class Drawers : UserControl
2425
public Drawers()
2526
{
2627
InitializeComponent();
27-
var xmlDoc = new XmlDocument();
28-
xmlDoc.Load(@"C:\Users\User\Desktop\MaterialDesignXAMLToolKitNew\MaterialDesignInXamlToolkit\MainDemo.Wpf\Drawers.xaml");
29-
this.XamlDisplayerPanel.Initialize(xmlDoc);
28+
XamlDisplayerPanel.Initialize(new SourceRouter(this.GetType().Name).GetSource());
3029
}
3130
}
3231
}

MainDemo.Wpf/Helper/SourceRouter.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Xml;
8+
using CodeDisplayer;
9+
10+
namespace MaterialDesignDemo.Helper {
11+
public class SourceRouter {
12+
private string _typeName;
13+
private const bool GetFromLocalSource = true;
14+
public SourceRouter(string typeName) {
15+
_typeName = typeName;
16+
}
17+
18+
public XmlDocument GetSource() {
19+
if (GetFromLocalSource)
20+
return Local();
21+
else
22+
return Remote();
23+
}
24+
public XmlDocument Local() {
25+
var xmlDoc = new XmlDocument();
26+
string source = File.ReadAllText($@"..\..\{_typeName}.xaml");
27+
xmlDoc.LoadXml(source);
28+
return xmlDoc;
29+
}
30+
31+
public XmlDocument Remote() {
32+
return new MaterialDesignInXamlToolkitGitHubFile(_typeName).GetXmlDocument();
33+
34+
}
35+
}
36+
}

MainDemo.Wpf/MaterialDesignDemo.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@
5151
<Paket>True</Paket>
5252
<Link>VirtualCollection/VirtualizingWrapPanel.cs</Link>
5353
</Compile>
54-
<Reference Include="CodeDisplayer, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
55-
<SpecificVersion>False</SpecificVersion>
56-
<HintPath>ExternalDependency\CodeDisplayer.dll</HintPath>
57-
</Reference>
5854
<Reference Include="PresentationFramework.Aero2" />
5955
<Reference Include="System" />
6056
<Reference Include="System.Configuration" />
@@ -136,6 +132,7 @@
136132
<Compile Include="GroupBoxes.xaml.cs">
137133
<DependentUpon>GroupBoxes.xaml</DependentUpon>
138134
</Compile>
135+
<Compile Include="Helper\SourceRouter.cs" />
139136
<Compile Include="Home.xaml.cs">
140137
<DependentUpon>Home.xaml</DependentUpon>
141138
</Compile>
@@ -414,6 +411,10 @@
414411
<None Include="App.config" />
415412
</ItemGroup>
416413
<ItemGroup>
414+
<ProjectReference Include="..\..\..\..\Source\Repos\Displaying-XAML\WpfApplication1\CodeDisplayer\CodeDisplayer.csproj">
415+
<Project>{ab0aca42-1c9f-4823-a8c9-4594c5b70f4e}</Project>
416+
<Name>CodeDisplayer</Name>
417+
</ProjectReference>
417418
<ProjectReference Include="..\MaterialDesignColors.Wpf\MaterialDesignColors.Wpf.csproj">
418419
<Project>{90b53209-c60c-4655-b28d-a1b3e1044ba3}</Project>
419420
<Name>MaterialDesignColors.Wpf</Name>

MainDemo.Wpf/TextFields.xaml.cs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel;
4-
using System.Linq;
5-
using System.Runtime.CompilerServices;
6-
using System.Text;
7-
using System.Threading.Tasks;
8-
using System.Windows;
1+
using System.Windows;
92
using System.Windows.Controls;
10-
using System.Windows.Data;
11-
using System.Windows.Documents;
12-
using System.Windows.Input;
13-
using System.Windows.Media;
14-
using System.Windows.Media.Imaging;
15-
using System.Windows.Navigation;
16-
using System.Windows.Shapes;
17-
using System.Windows.Threading;
183
using System.Xml;
19-
using CodeDisplayer;
204
using MaterialDesignColors.WpfExample.Domain;
5+
using MaterialDesignDemo.Helper;
216

227
namespace MaterialDesignColors.WpfExample
238
{
@@ -30,16 +15,7 @@ public TextFields()
3015
{
3116
InitializeComponent();
3217
DataContext = new TextFieldsViewModel();
33-
var xmlDoc = new XmlDocument();
34-
xmlDoc.Load(@"..\..\TextFields.xaml");
35-
//XmlDocument xmlDoc =
36-
// new MaterialDesignInXamlToolkitGitHubFile(
37-
// ownerName: "wongjiahau" ,
38-
// branchName: "New-Demo-2" ,
39-
// fileName: "TextFields.xaml")
40-
// .GetXmlDocument();
41-
XamlDisplayerPanel.Initialize(xmlDoc);
42-
18+
XamlDisplayerPanel.Initialize(new SourceRouter(this.GetType().Name).GetSource());
4319
}
4420

4521
private void UserControl_Loaded(object sender, RoutedEventArgs e)

0 commit comments

Comments
 (0)