Skip to content

Commit 3e55f52

Browse files
committed
Sample app now switches to Commands List pivot item to show the parsing error.
1 parent b7a9fed commit 3e55f52

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/CanvasPathGeometry/CanvasPathGeometryPage.xaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,6 @@
8585
HorizontalAlignment="Left"
8686
Click="{x:Bind OnClearCanvas}"
8787
Content="Clear" />
88-
<TextBlock x:Name="ParseError"
89-
Grid.Row="3"
90-
Margin="150,3,10,3"
91-
HorizontalAlignment="Stretch"
92-
VerticalAlignment="Center"
93-
FontSize="16"
94-
Foreground="Red"
95-
TextAlignment="Left" />
9688
<Pivot x:Name="RootPivot"
9789
Grid.Row="4">
9890
<PivotItem Foreground="Black"

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/CanvasPathGeometry/CanvasPathGeometryPage.xaml.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Windows.UI.Xaml;
1616
using Windows.UI.Xaml.Controls;
1717
using Windows.UI.Xaml.Controls.Primitives;
18+
using Windows.UI.Xaml.Media;
1819

1920
namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
2021
{
@@ -99,6 +100,9 @@ public sealed partial class CanvasPathGeometryPage : Page
99100
private CanvasGeometry _errorGeometry;
100101
private GeometryStreamReader _reader;
101102

103+
private SolidColorBrush _commandBrush;
104+
private SolidColorBrush _commandErrorBrush;
105+
102106
public string InputText { get; set; }
103107

104108
public CanvasPathGeometryPage()
@@ -119,6 +123,9 @@ public CanvasPathGeometryPage()
119123
CanvasPathGeometry.CreateColor("#ffd60a")
120124
};
121125

126+
_commandBrush = new SolidColorBrush(Colors.White);
127+
_commandErrorBrush = new SolidColorBrush(Colors.Red);
128+
122129
var colorList = new List<string>()
123130
{
124131
"Transparent",
@@ -174,7 +181,6 @@ private void OnCanvasDraw(CanvasControl sender, CanvasDrawEventArgs args)
174181
{
175182
if (string.IsNullOrWhiteSpace(_data))
176183
{
177-
ParseError.Text = string.Empty;
178184
CommandsList.Text = string.Empty;
179185
return;
180186
}
@@ -183,7 +189,6 @@ private void OnCanvasDraw(CanvasControl sender, CanvasDrawEventArgs args)
183189

184190
_logger?.Clear();
185191
CommandsList.Text = string.Empty;
186-
ParseError.Text = string.Empty;
187192

188193
try
189194
{
@@ -197,40 +202,46 @@ private void OnCanvasDraw(CanvasControl sender, CanvasDrawEventArgs args)
197202

198203
args.DrawingSession.FillGeometry(geometry, _fillColor);
199204
args.DrawingSession.DrawGeometry(geometry, _strokeColor, _strokeThickness);
205+
RootPivot.SelectedIndex = 0;
206+
CommandsList.Foreground = _commandBrush;
200207
}
201208
catch (ArgumentException argEx)
202209
{
203210
var message = argEx.Message;
204211
var errorCode = message.Substring(0, 11);
212+
var parseError = string.Empty;
205213
if (message.StartsWith(ParseError1))
206214
{
207-
ParseError.Text = "Parse Error: No matching data!";
215+
parseError = "Parse Error: No matching data!";
208216
}
209217
else if (message.StartsWith(ParseError2))
210218
{
211-
ParseError.Text = "Parse Error: Multiple FillRule elements present in Path Data!";
219+
parseError = "Parse Error: Multiple FillRule elements present in Path Data!";
212220
}
213221
else if (message.StartsWith(ParseError3))
214222
{
215223
var tokens = message.Split('\n', StringSplitOptions.RemoveEmptyEntries);
216224
if (tokens.Length == 3)
217225
{
218-
ParseError.Text = $"Parse Error at {tokens[1]}. Cannot parse '{tokens[2]}'.";
226+
parseError = $"Parse Error at {tokens[1]}. Cannot parse '{tokens[2]}'.";
219227
}
220228
}
221229
else
222230
{
223-
ParseError.Text = "Parsing error! Invalid input data!";
231+
parseError = "Parsing error! Invalid input data!";
224232
}
225233

226234
args.DrawingSession.FillGeometry(_errorGeometry, Colors.Black);
227-
CommandsList.Text = ParseError.Text;
235+
CommandsList.Text = parseError;
236+
RootPivot.SelectedIndex = 1;
237+
CommandsList.Foreground = _commandErrorBrush;
228238
}
229239
catch (Exception)
230240
{
231241
args.DrawingSession.FillGeometry(_errorGeometry, Colors.Black);
232-
ParseError.Text = "Parsing error! Invalid input data!";
233242
CommandsList.Text = "Parsing error! Invalid input data!";
243+
RootPivot.SelectedIndex = 1;
244+
CommandsList.Foreground = _commandErrorBrush;
234245
}
235246
}
236247

0 commit comments

Comments
 (0)