Der aktive Knopf mit CommandBindings

 

 

 

MainWindow.xaml:

<Window x:Class="ButtonAktivCheckBox.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ButtonAktivCheckBox"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<CheckBox x:Name="checkBox1" Content="Adresse ändern ?" Margin="0,0,0,5" />

<Button Command="local:AktiverKnopf.Launch" Content="Adresse ändern ..." Width="250" Height="30">
<Button.CommandBindings>
<CommandBinding Command="{x:Static local:AktiverKnopf.Launch}"
Executed="CommandBinding_Executed"
CanExecute="CommandBinding_CanExecute" />
</Button.CommandBindings>
</Button>
</StackPanel>
</Grid>
</Window>

 

 


MainWindow.xaml.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 ButtonAktivCheckBox
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
MessageBox.Show("Sie sind im Begriff die Daten zu ändern ...");
}

private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = (bool)checkBox1.IsChecked;
}
}
}

 

 


AktiverKnopf.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace ButtonAktivCheckBox
{
public class AktiverKnopf
{
private static RoutedUICommand _launch;

public static RoutedUICommand Launch
{
get
{
return _launch;
}
}

static AktiverKnopf()
{
_launch = new RoutedUICommand("Mein aktiver Knopf", "Launch", typeof(AktiverKnopf));
Launch.InputGestures.Add(new KeyGesture(Key.L, ModifierKeys.Control));
}
}
}

Top