112 lines
4.1 KiB
C#
112 lines
4.1 KiB
C#
using KanSan.Base.Models;
|
|
using KanSan.ViewModel;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Text;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
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>
|
|
public partial class UCObjekteList : UserControl
|
|
{
|
|
public event EventHandler<ObjektSelectEventArgs> ObjektSelected;
|
|
Baustelle baustelle;
|
|
public UCObjekteList()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
public UCObjekteList(Baustelle baustelle)
|
|
{
|
|
InitializeComponent();
|
|
this.baustelle = baustelle;
|
|
this.DataContext = new ObjekteListViewModel(baustelle);
|
|
}
|
|
|
|
private void ObjektNew_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
FrmNewObjekt frmNewObjekt = new FrmNewObjekt(baustelle);
|
|
frmNewObjekt.ShowDialog();
|
|
}
|
|
|
|
private void trvItems_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
|
{
|
|
TreeView treeView = (TreeView)sender;
|
|
if (treeView == null) return;
|
|
if (!(treeView.SelectedItem is Sewer)) return;
|
|
Sewer sewer = (Sewer)treeView.SelectedItem;
|
|
if (sewer == null) return;
|
|
OnObjektSelectKlick(new ObjektSelectEventArgs() { Objekt = sewer });
|
|
}
|
|
|
|
protected virtual void OnObjektSelectKlick(ObjektSelectEventArgs e)
|
|
{
|
|
EventHandler<ObjektSelectEventArgs> handler = ObjektSelected;
|
|
if (handler != null)
|
|
handler(this, e);
|
|
}
|
|
}
|
|
|
|
public class ObjektSelectEventArgs : EventArgs
|
|
{
|
|
public Sewer Objekt { get; set; }
|
|
}
|
|
}
|