Umbau angefangen auf ICommand

This commit is contained in:
Husky
2020-07-12 19:32:14 +02:00
parent 9f8e167ce3
commit 3e9a353fc0
33 changed files with 342 additions and 77 deletions

View File

@@ -16,6 +16,52 @@ using System.Windows.Shapes;
namespace KanSan.UI
{
public class MouseLeftButtonUp
{
public static DependencyProperty CommandProperty = DependencyProperty.RegisterAttached("Command", typeof(ICommand), typeof(MouseLeftButtonUp), new UIPropertyMetadata(CommandChanged));
public static DependencyProperty CommandParameterProperty =
DependencyProperty.RegisterAttached("CommandParamter",
typeof(object),
typeof(MouseLeftButtonUp),
new UIPropertyMetadata(null));
public static void SetCommand(DependencyObject target, ICommand value)
{
target.SetValue(CommandProperty, value);
}
public static object GetCommand(DependencyObject target, ICommand value)
{
return target.GetValue(CommandProperty);
}
public static void SetCommandParamter(DependencyObject target, object value)
{
target.SetValue(CommandProperty, value);
}
public static object GetCommandParamter(DependencyObject target)
{
return target.GetValue(CommandParameterProperty);
}
private static void CommandChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
{
//throw new NotImplementedException();
Control control = target as Control;
if (control == null) return;
if ((e.NewValue != null) && (e.OldValue == null))
control.MouseLeftButtonUp += OnMouseLeftButtonUp;
else if ((e.NewValue == null) && (e.OldValue != null))
control.MouseLeftButtonUp -= OnMouseLeftButtonUp;
}
private static void OnMouseLeftButtonUp(object sender, RoutedEventArgs e)
{
//throw new NotImplementedException();
Control control = sender as Control;
ICommand command = (ICommand)control.GetValue(CommandProperty);
object commandParameter = control.GetValue(CommandParameterProperty);
command.Execute(commandParameter);
e.Handled = true;
}
}
/// <summary>
/// Interaktionslogik für UCObjekteList.xaml
/// </summary>
@@ -23,6 +69,10 @@ namespace KanSan.UI
{
public event EventHandler<ObjektSelectEventArgs> ObjektSelected;
Baustelle baustelle;
public UCObjekteList()
{
InitializeComponent();
}
public UCObjekteList(Baustelle baustelle)
{
InitializeComponent();