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

@@ -19,7 +19,14 @@
<RowDefinition Height="50" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<TreeView Name="trvItems" ItemsSource="{Binding KanalObjekte}" MouseDoubleClick="trvItems_MouseDoubleClick">
<TreeView Name="trvItems" ItemsSource="{Binding KanalObjekte}" >
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="local:MouseLeftButtonUp.Command" Value="{Binding DataContext.ObjektSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeView}}}" />
<Setter Property="local:MouseLeftButtonUp.CommandParamter"
Value="{Binding ElementName=trvItems, Path=SelectedItem}"/>
</Style>
</TreeView.ItemContainerStyle>
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type self:ObjekteTransfer}" ItemsSource="{Binding Objekte}">
<StackPanel Orientation="Horizontal">

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();