-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddFields.cs
More file actions
32 lines (27 loc) · 1.06 KB
/
AddFields.cs
File metadata and controls
32 lines (27 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Windows;
using System.Windows.Controls;
public class AddFields
{
public static void AddFieldsToPanel(StackPanel panel, AdLib[] adLibs)
{
// special character arrays to be removed from ad libs for label usage
char[] startChars = new char[] { '[', '*' };
char[] endChars = new char[] { ']', '*' };
AdLibField? entry;
for (int i = 0; i < adLibs.Length; i++)
{
entry = new AdLibField(adLibs[i].adLib.TrimStart(startChars).TrimEnd(endChars));
// check if label content is empty
if (entry.textBlock.Text == "")
{
// throw exception
throw new Exception("Error in AddFieldsToPanel: Text block content is empty.");
}
// make first character of entry textBlock uppercase
entry.textBlock.Text = entry.textBlock.Text.Substring(0, 1).ToUpper() + entry.textBlock.Text.Substring(1);
panel.Children.Add(entry.textBlock);
panel.Children.Add(entry.textBox);
}
}
}