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; } } /// /// Interaktionslogik für UCObjekteList.xaml /// public partial class UCObjekteList : UserControl { 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; SewerMainWindow sewerMainWindow = new SewerMainWindow(); sewerMainWindow.DataContext = new SewerMainWindowViewModel(sewer); sewerMainWindow.ShowDialog(); } } }