public void SetSettingsFromUI(TyrantSettings settings) { var grid = (Grid)Content; foreach (var item in grid.Children) { if (item is CheckBox checkbox) { // Use default XAML value to determine if it this is default to on/off settings[checkbox.Name] = checkbox.IsChecked == true ? "Yes" : "No"; } else if (item is TextBox box) { if (box.Name.StartsWith("Float")) { settings[box.Name.Substring(5)] = float.TryParse(box.Text, out var val) ? box.Text : "1.0"; } else if (box.Name.StartsWith("Integer")) { settings[box.Name.Substring(7)] = int.TryParse(box.Text, out var val) ? box.Text : "1"; } else { settings[box.Name] = box.Text; } } } }
public void SetUIFromSettings(TyrantSettings settings) { var grid = (Grid)Content; foreach (var item in grid.Children) { if (item is CheckBox checkbox) { // Use default XAML value to determine if it this is default to on/off checkbox.IsChecked = settings[checkbox.Name, checkbox.IsChecked == true ? "Yes" : "No"] == "Yes"; } else if (item is TextBox box) { if (box.Name.StartsWith("Float")) { box.Text = settings[box.Name.Substring(5), "1.0"]; } else if (box.Name.StartsWith("Integer")) { box.Text = settings[box.Name.Substring(7), "1"]; } else { box.Text = settings[box.Name, ""]; } } } }