mirror of
https://github.com/holgerb83/ModernWpfPlayground.git
synced 2025-04-16 21:43:51 +02:00
39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using System;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
|
|
namespace LsBricks.Controls
|
|
{
|
|
/// <summary>
|
|
/// Selects the right template on base of value-type.
|
|
/// </summary>
|
|
public class PropertyDataTemplateSelector : DataTemplateSelector
|
|
{
|
|
/// <summary>
|
|
/// Default data template. (currently Textbox)
|
|
/// </summary>
|
|
public DataTemplate DefaultDataTemplate { private get; set; }
|
|
|
|
/// <summary>
|
|
/// Data template for boolean. (currently Checkbox)
|
|
/// </summary>
|
|
public DataTemplate BooleanDataTemplate { private get; set; }
|
|
|
|
/// <summary>
|
|
/// Data template for enums. (currently Combobox)
|
|
/// </summary>
|
|
public DataTemplate EnumComboBoxDataTemplate { private get; set; }
|
|
|
|
/// <inheritdoc />
|
|
public override DataTemplate SelectTemplate(object item, DependencyObject container)
|
|
{
|
|
return item switch
|
|
{
|
|
bool _ => BooleanDataTemplate,
|
|
Enum _ => EnumComboBoxDataTemplate,
|
|
UIElement _ => null,
|
|
_ => DefaultDataTemplate
|
|
};
|
|
}
|
|
}
|
|
} |