Skip to content

Commit

Permalink
Add DropdownWindow and standardize window properties
Browse files Browse the repository at this point in the history
Introduce a new `DropdownWindow` class that uses a custom dropdown control, and standardize the width, height, and startup location properties for all windows. Adjustments in the `Dropdown` control improve type safety and data handling.
  • Loading branch information
frankhaugen committed Aug 12, 2024
1 parent 121a731 commit 5814c94
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 20 deletions.
20 changes: 7 additions & 13 deletions Frank.Wpf.Controls.SimpleInputs/Dropdown.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Diagnostics;
using System.Windows;
using System.Windows;
using System.Windows.Controls;
using Frank.Wpf.Core;

namespace Frank.Wpf.Controls.SimpleInputs;

Expand All @@ -23,18 +21,14 @@ public required IEnumerable<T> Items

public required Func<T, string> DisplayFunc
{
init
{
_comboBox.DisplayMemberPath = nameof(ComboBoxItem.Content);
_comboBox.ItemTemplate = CreateDataTemplate(value);
}
init => _comboBox.ItemTemplate = CreateDataTemplate(value);
}

public required Action<T> SelectionChangedAction { get; init; }

private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (_comboBox.SelectedItem is T selectedItem && SelectionChangedAction != null)
if (_comboBox.SelectedItem is T selectedItem)
{
SelectionChangedAction(selectedItem);
}
Expand Down Expand Up @@ -63,14 +57,14 @@ public FuncValueConverter(Func<TInput, TOutput> func)
_func = func;
}

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
public object? Convert(object? value, Type targetType, object? parameter, System.Globalization.CultureInfo culture)
{
return value is TInput input ? _func(input) : default;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
public object? ConvertBack(object? value, Type targetType, object? parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
return value is TOutput output ? output : default;
}
}
}
63 changes: 56 additions & 7 deletions Frank.Wpf.Tests.App/DefaultWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows.Controls;
using System.Windows;
using System.Windows.Controls;
using Frank.Wpf.Controls.SimpleInputs;
using Frank.Wpf.Hosting;
using Frank.Wpf.Tests.App.Windows;
Expand All @@ -11,42 +12,90 @@ public class DefaultWindow : MainWindow

public DefaultWindow()
{
var defaultWidth = 400;
var defaultHeight = 300;
var defaultPosition = WindowStartupLocation.CenterScreen;

Title = "Frank.Wpf.Tests.App";
Content = _windowButtons;
Width = defaultWidth;
Height = defaultHeight;
WindowStartupLocation = defaultPosition;

_windowButtons.AddButton("Show SQL Runner", (sender, args) =>
{
var window = new SqlLiteWindow();
var window = new SqlLiteWindow
{
Width = defaultWidth,
Height = defaultHeight,
WindowStartupLocation = defaultPosition
};
window.Show();
});

_windowButtons.AddButton("Show Json Window", (sender, args) =>
{
var window = new JsonWindow();
var window = new JsonWindow
{
Width = defaultWidth,
Height = defaultHeight,
WindowStartupLocation = defaultPosition
};
window.Show();
});

_windowButtons.AddButton("Show Console Window", (sender, args) =>
{
var window = new ConsoleWindow();
var window = new ConsoleWindow
{
Width = defaultWidth,
Height = defaultHeight,
WindowStartupLocation = defaultPosition
};
window.Show();
});

_windowButtons.AddButton("Show Custom List Box Window", (sender, args) =>
{
var window = new CustomListBoxWindow();
var window = new CustomListBoxWindow
{
Width = defaultWidth,
Height = defaultHeight,
WindowStartupLocation = defaultPosition
};
window.Show();
});

_windowButtons.AddButton("Show Searchable Selection List Window", (sender, args) =>
{
var window = new SearchableSelectionListWindow();
var window = new SearchableSelectionListWindow
{
Width = defaultWidth,
Height = defaultHeight,
WindowStartupLocation = defaultPosition
};
window.Show();
});

_windowButtons.AddButton("Show Key-Value Pair Editor Window", (sender, args) =>
{
var window = new KvpEditorWindow();
var window = new KvpEditorWindow
{
Width = defaultWidth,
Height = defaultHeight,
WindowStartupLocation = defaultPosition
};
window.Show();
});

_windowButtons.AddButton("Show Dropdown Window", (sender, args) =>
{
var window = new DropdownWindow
{
Width = defaultWidth,
Height = defaultHeight,
WindowStartupLocation = defaultPosition
};
window.Show();
});
}
Expand Down
40 changes: 40 additions & 0 deletions Frank.Wpf.Tests.App/Windows/DropdownWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Windows;
using System.Windows.Controls;
using Frank.Wpf.Controls.SimpleInputs;

namespace Frank.Wpf.Tests.App.Windows;

public class DropdownWindow : Window
{

private readonly Dropdown<MyClass> _dropdown;

public DropdownWindow()
{
_dropdown = new Dropdown<MyClass>()
{
Items = new List<MyClass>
{
new MyClass { Id = Guid.NewGuid(), Name = "Frank", Age = 30 },
new MyClass { Id = Guid.NewGuid(), Name = "John", Age = 40 },
new MyClass { Id = Guid.NewGuid(), Name = "Jane", Age = 50 }
},
DisplayFunc = x => x.Name,
SelectionChangedAction = x => { MessageBox.Show($"Selected {x.Name} with Id {x.Id} and Age {x.Age}"); }
};

var stackPanel = new StackPanel();
stackPanel.Children.Add(_dropdown);

Content = stackPanel;
}

private class MyClass
{
public Guid Id { get; set; }

public string Name { get; set; }

public int Age { get; set; }
}
}

0 comments on commit 5814c94

Please sign in to comment.