У меня недостаточно понимания, как использовать интерфейс ICommand для выполнения нескольких методов подряд. В идеале я хотел бы создать делегат, который выполняет все следующие 4 метода, вызывая его (но это не обязательно должен быть делегат):
var mongo = DbConn(); //Connection to MongoDB
var artikel = GetArtikel(reorderView); //returns ObservableCollection<ArtikelModel>
var reorder = GetReorder(artikel, reorderView); //returns ReorderModel
Insert(mongo, artikel, reorder); //inserts new reorder into the MongoDB database (one reorder has multiple articles(artikel))
Представление (отрывок):
<Button Name="btnSave" Margin="3,0,3,0" Content="Save Reorder"
BorderThickness="0" BorderBrush="Green"
Height="30" FontWeight="Bold" FontSize="15"
Background="Green"
VerticalAlignment="Top"
Command="{Binding SaveNb}">
</Button>
Код сзади:
public partial class addReorder : System.Windows.Window
{
ReorderViewModel nachbest;
ArtikelViewModel artikel;
//IControllerNachbestellung controllerNachbestellung;
//IModelNachbestellung modelNachbestellung;
public ObservableCollection<string> AnfCollection { get; set; }
public addReorder()
{
this.DataContext = new addReorderViewModel();
}
public addReorder(string hv)
{
InitializeComponent();
//HV, BV, Projektleiter und Bauleiter holen
var dbOracle = new Datenbank();
txtBv.Text = dbOracle.GetBauvorhaben(hv);
txtbHv.Text = hv;
txtBauleiter.Text = dbOracle.GetBauleiter(hv);
string pl = dbOracle.GetProjektleiter(hv);
txtProjektleiter.Text = dbOracle.GetProjektleiter(hv);
nachbest = new ReorderViewModel();
artikel = new ArtikelViewModel();
leftStPnl.DataContext = nachbest;
rightStPnl.DataContext = nachbest;
dgArtikel.DataContext = artikel;
//Die Anforderungscollection wird befüllt
IAnforderungsgrund anfgruende = new Anforderungsgrund();
AnfCollection = anfgruende.ListeAnforderungen();
dgcbAnf.ItemsSource = AnfCollection;
dgcbAnf.TextBinding = new Binding(AnfCollection.ToString());
}
}
Модель представления (нужна помощь здесь):
public class addReorderViewModel
{
//Hook to class DelegateCommand
private readonly DelegateCommand<Button> _clickCommand;
private ICommand saveNb { get; set; }
public addReorderViewModel(addReorderView reorderview)
{
}
public ICommand SaveNb
{
get
{
return saveNb;
}
set
{
saveNb = value;
}
}
ViewModel имеет «крючок» для класса DelegateCommand.cs: DelegateCommand.cs
public class DelegateCommand<T> : System.Windows.Input.ICommand
{
private readonly Predicate<T> _canExecute;
private readonly Action<T> _execute;
public DelegateCommand(Action<T> execute)
: this(execute, null)
{
}
public DelegateCommand(Action<T> execute, Predicate<T> canExecute)
{
_execute = execute;
_canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
if (_canExecute == null)
return true;
return _canExecute((parameter == null) ? default(T) : (T)Convert.ChangeType(parameter, typeof(T)));
}
public void Execute(object parameter)
{
_execute((parameter == null) ? default(T) : (T)Convert.ChangeType(parameter, typeof(T)));
}
public event EventHandler CanExecuteChanged;
public void RaiseCanExecuteChanged()
{
if (CanExecuteChanged != null)
CanExecuteChanged(this, EventArgs.Empty);
}
}
Вопросы:
Что мне нужно сделать, чтобы нажатие кнопки выполняло вышеупомянутые 4 метода?
Как добавить другие события нажатия кнопки (представление имеет около 5-10кнопки) в ViewModel?
Как ViewModel узнает о текущем открытом представлении?
Методы внутриViewModel:
public MongoCRUD DbConn()
{
//Connection to MongoDB database "avdb"
var mongo = new MongoCRUD("avdb");
return mongo; //return value needed for INSERT-METHOD!
}
public ObservableCollection<Artikel> GetArtikel()
{
//How many rows inside the datagrid dgArtikel?
int countrows = view.dgArtikel.Items.Count;
//How many Columns?
int countcols = view.dgArtikel.Columns.Count;
//Arrays
DataGridRow[] row = new DataGridRow[countrows];
DataGridCell[] RowColumn = new DataGridCell[countcols];
string[] CellValue = new string[countcols];
string[,] ds = new string[countrows, countcols];
ObservableCollection<Artikel> artikel = new ObservableCollection<Artikel>() { };
//Save all cell values inside multidimensional Array
for (int i = 0; i < countrows; i++)
{
//Create object for each DataGridRow of dgArtikel
row[i] = (DataGridRow)view.dgArtikel.ItemContainerGenerator.ContainerFromIndex(i);
//Alle Spalten in der jeweiligen Zeile iterieren
for (int j = 0; j < view.dgArtikel.Columns.Count; j++)
{
RowColumn[j] = view.dgArtikel.Columns[j].GetCellContent(row[i]).Parent as DataGridCell;
//ATTENTION HARDCODING --> j==INDEX COMBOBOXCOLUMN!!!
if (j == 7) //<---!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
{
CellValue[j] = ((ComboBox)RowColumn[j].Content).Text;
}
else
{
CellValue[j] = ((TextBlock)RowColumn[j].Content).Text;
}
ds[i, j] = CellValue[j];
}
//The sequence must be the same as inside class ARTIKEL! ATTENTION HARDCODING!
var art = new Artikel
{
Pos = ds[i, 0],
Artikelbezeichnung = ds[i, 1],
Artikelnummer = ds[i, 2],
Einheit = ds[i, 3],
Menge = ds[i, 4],
Einzelpreis = ds[i, 5],
Gesamtpreis = ds[i, 6],
Anforderungsgrund = ds[i, 7], //<---!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Anforderungsnr = ds[i, 8],
Anforderer = ds[i, 9],
Bemerkungen = ds[i, 10]
};
if (art != null)
artikel.Add(art);
}
return artikel;
}
public ReorderModel GetReorder(ObservableCollection<Artikel> artikel, addReorderView reorderview)
{
ReorderModel rom = new ReorderModel
{
Hv = view.txtbHv.Text,
Bv = view.txtBv.Text,
Bauleiter = view.txtBauleiter.Text,
Empfaenger = view.cboxEmpfaenger.Text,
Empf_Ansprechpartner = view.txtEmpfAnsprechpartner.Text,
Empfaenger_Mail = view.txtEmpfMail.Text,
Anlieferungsort = view.cboxAnlieferung.Text,
Adressat = view.cboxAdressat.Text,
Anschrift = view.txtAdresse.Text,
Plz_Ort = view.txtPlzOrt.Text,
Kontaktperson_Kontaktnr = view.txtAnsprechpartnerOrt.Text,
Liefertermin = view.calLiefertermin.Text,
Bearbeiter = view.cboxBearbeiter.Text,
Telefon_Bearbeiter = view.txtBearbeiterTel.Text,
Mail_Bearbeiter = view.txtBearbeiterMail.Text,
Bestelldatum = view.calBestelldatum.Text,
Bemerkung_oben = view.txtBemerkung.Text,
Projektleiter = view.txtProjektleiter.Text,
Angelegt_am = DateTime.Now.ToString(),
artikelliste = artikel
};
return rom;
}
public void Insert(MongoCRUD mongo, ObservableCollection<Artikel> artikel, ReorderModel rom)
{
foreach (var a in artikel)
{
mongo.InsertRecord<Artikel>("bestellteArtikel", a);
}
mongo.InsertRecord<Nachbestellung>("nachbestellungen", nb);
MessageBox.Show("Nachbestellung in Datenbank gespeichert!", "Erfolgreich!", MessageBoxButton.OK, MessageBoxImage.Information);
}
Это дизайн вида: Это сетка данных в дизайне вида (пример-пустышка)
ЗЕЛЕНАЯ КНОПКА - это ВСТАВКА, которую я хочу выполнить с помощью интерфейса ICommand, т. Е. Сделайте следующее после нажатия:
Подключение к MongoDB
Получите мне observableCollection ()
Получите мне экземпляр ReorderModel
Вставьте в мою базу данных коллекцию
XAML:
<Window x:Class="Nachbestellungen.neueNachbestellung"
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:Nachbestellungen"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
FontFamily="Arial Narrow"
Title="Nachbestellungen" Height="900" Width="900" FontWeight="Bold">
<Window.Resources>
<!-- Abstand zwischen Textblock und Textbox automatisch setzen -->
<Style TargetType="TextBox">
<Setter Property="Margin" Value="0,0,0,0"/>
</Style>
</Window.Resources>
<Grid Name="uInputGrid">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<!-- links -->
<StackPanel Grid.Column="0" Margin="25,25,0,0" x:Name="leftStPnl">
<StackPanel x:Name="pnlHeader" Grid.Column="0" Grid.Row="0" Orientation="Vertical">
<TextBlock Name="tbNb" Grid.Row="0" Grid.Column="0" Text="NACHBESTELLUNG" FontWeight="Bold" FontSize="20"/>
</StackPanel>
<StackPanel x:Name="pnlBv" Grid.Column="0" Grid.Row="1" Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Name="tbBv" Text="Bauvorhaben" DockPanel.Dock="Left" FontSize="14" FontWeight="Bold"/>
<TextBox Name="txtBv" FontSize="12" DockPanel.Dock="Right" IsEnabled="False" Width="150" Margin="68,0,0,0"></TextBox>
</StackPanel>
<StackPanel x:Name="pnlHv" Grid.Column="0" Grid.Row="2" Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Name="tbHv" Grid.Column="0" Text="HV-Nummer" FontSize="14" FontWeight="Bold"/>
<TextBox x:Name="txtbHv" FontSize="12" IsEnabled="False" Width="60" Margin="72,0,0,0"/>
</StackPanel>
<StackPanel x:Name="pnlBauleiter" Grid.Column="0" Grid.Row="3" Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Name="tbBauleiter" Text="Bauleiter" FontSize="14" FontWeight="Bold"/>
<TextBox x:Name="txtBauleiter" FontSize="12" IsEnabled="False" Width="150" Margin="90,0,0,0"/>
</StackPanel>
<StackPanel x:Name="pnlGap1" Grid.Column="0" Grid.Row="4" Margin="0,10,0,0" Orientation="Horizontal">
</StackPanel>
<StackPanel x:Name="pnlEmpfaenger" Grid.Column="0" Grid.Row="5" Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Name="tbEmpfaenger" Text="AN" FontSize="14" FontWeight="Bold"/>
<ComboBox x:Name="cboxEmpfaenger" FontSize="12" Width="150" Margin="118,0,0,0" Loaded="ComboBox_Loaded" SelectionChanged="ComboBox_Changed">
</ComboBox>
</StackPanel>
<StackPanel x:Name="pnlEmpfAnsprechpartner" Grid.Column="0" Grid.Row="6" Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Name="tbEmpfAnsprechpartner" Text="Ansprechpartner" FontSize="14" FontWeight="Bold"/>
<TextBox x:Name="txtEmpfAnsprechpartner" FontSize="12" IsEnabled="False" Width="150" Margin="50,0,0,0"/>
</StackPanel>
<StackPanel x:Name="pnlEmpfMail" Grid.Column="0" Grid.Row="7" Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Name="tbEmpfMail" Text="Mailadresse" FontSize="14" FontWeight="Bold"/>
<TextBox x:Name="txtEmpfMail" FontSize="12" IsEnabled="False" Width="150" Margin="73,0,0,0"/>
</StackPanel>
<StackPanel x:Name="pnlGap2" Grid.Column="0" Grid.Row="8" Margin="0,10,0,0" Orientation="Horizontal">
</StackPanel>
<StackPanel x:Name="pnlAnlieferung" Grid.Column="0" Grid.Row="9" Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Name="tbAnlieferung" Text="Anlieferung" FontSize="14" FontWeight="Bold"/>
<ComboBox x:Name="cboxAnlieferung" FontSize="12" Width="150" Margin="77,0,0,0" Loaded="ComboBoxAnlieferung_Loaded" SelectionChanged="ComboBoxAnlieferung_Changed"/>
</StackPanel>
<StackPanel x:Name="pnlBauherr" Grid.Column="0" Grid.Row="10" Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Name="tbBauherr" FontSize="14" FontWeight="Bold"/>
<ComboBox x:Name="cboxAdressat" FontSize="12" IsEnabled="False" Width="200" Margin="135,0,0,0" DropDownClosed="CboxAdressat_DropDownClosed"/>
</StackPanel>
<StackPanel x:Name="pnlAdresse" Grid.Column="0" Grid.Row="11" Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Name="tbAdresse" FontSize="14" FontWeight="Bold" Text="Adresse"/>
<TextBox x:Name="txtAdresse" FontSize="12" IsEnabled="False" Width="150" Margin="93,0,0,0"/>
</StackPanel>
<StackPanel x:Name="pnlPlzOrt" Grid.Column="0" Grid.Row="12" Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Name="tbPlzOrt" FontSize="14" FontWeight="Bold"/>
<TextBox x:Name="txtPlzOrt" FontSize="12" IsEnabled="False" Width="150" Margin="135,0,0,0"/>
</StackPanel>
<StackPanel x:Name="pnlGap3" Grid.Column="0" Grid.Row="13" Margin="0,10,0,0" Orientation="Horizontal">
</StackPanel>
<StackPanel x:Name="pnlAnsprechpartnerOrt" Grid.Column="0" Grid.Row="14" Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Name="tbAnsprechpartnerOrt" FontSize="14" FontWeight="Bold" Text="Ansprechpartner vor Ort/Telefon"/>
<TextBox x:Name="txtAnsprechpartnerOrt" FontSize="12" Width="190" Margin="50,0,0,0" AcceptsReturn="False"/>
<Button x:Name="btnKontakt" Content="Kontakt auswählen" FontSize="12" Click="btnKontakt_Click" />
</StackPanel>
<StackPanel x:Name="pnlBemerkung" Grid.Column="0" Grid.Row="14" Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Name="tbBemerkung" FontSize="14" FontWeight="Bold" Text="Bemerkung"/>
<TextBox x:Name="txtBemerkung" FontSize="12" Width="250" Height="40" Margin="76,0,0,0" AcceptsReturn="False"/>
</StackPanel>
<StackPanel x:Name="pnlLiefertermin" Grid.Column="0" Grid.Row="15" Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Name="tbLiefertermin" FontSize="14" FontWeight="Bold" Text="Liefertermin"/>
<DatePicker x:Name="calLiefertermin" FontSize="12" Width="160" Margin="75,0,0,0" IsTodayHighlighted="true"/>
</StackPanel>
</StackPanel>
<!--rechts-->
<StackPanel Grid.Column="1" Margin="0,25,25,0" x:Name="rightStPnl">
<StackPanel x:Name="pnlLuxLogo" Grid.Column="1" Grid.Row="0" Margin="0,10,0,0" Orientation="Vertical">
<Image Source="Z:\SchaeferT\Projekte\Haustechnik\Nachbestellungen\Nachbestellungen\LuxLogo.png" Width="200" Height="30" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel x:Name="pnlFirma" Grid.Column="1" Grid.Row="1" Margin="0,27,0,0" Orientation="Vertical">
<TextBlock x:Name="tbFirma" FontSize="12" Text="Lux Projektmanagement GmbH & Co. KG"/>
</StackPanel>
<StackPanel x:Name="pnlFirmaAnschrift" Grid.Column="1" Grid.Row="2" Margin="0,10,0,0" Orientation="Vertical">
<TextBlock x:Name="tbFirmaAnschrift" FontSize="12" Text="Pleinfelder Straße 64"/>
</StackPanel>
<StackPanel x:Name="pnlFirmaPlzOrt" Grid.Column="1" Grid.Row="3" Margin="0,10,0,0" Orientation="Vertical">
<TextBlock x:Name="tbFirmaPlzOrt" FontSize="12" Text="91166 Georgensgmünd"/>
</StackPanel>
<StackPanel x:Name="pnlRightGap1" Grid.Column="1" Grid.Row="4" Margin="0,10,0,0" Orientation="Horizontal">
</StackPanel>
<StackPanel x:Name="pnlBearbeiter" Grid.Column="1" Grid.Row="5" Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Name="tbBearbeiter" FontSize="14" FontWeight="Bold" Text="Bearbeiter"/>
<ComboBox x:Name="cboxBearbeiter" FontSize="12" Width="150" Margin="30,0,0,0" Loaded="ComboBoxBearbeiter_Loaded" SelectionChanged="ComboBoxBearbeiter_Changed"/>
</StackPanel>
<StackPanel x:Name="pnlBearbeiterTel" Grid.Column="0" Grid.Row="6" Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Name="tbBearbeiterTel" FontSize="14" FontWeight="Bold" Text="Telefon"/>
<TextBox x:Name="txtBearbeiterTel" FontSize="12" IsEnabled="False" Width="150" Margin="45,0,0,0"/>
</StackPanel>
<StackPanel x:Name="pnlBearbeiterMail" Grid.Column="0" Grid.Row="7" Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Name="tbBearbeiterMail" FontSize="14" FontWeight="Bold" Text="Mail"/>
<TextBox x:Name="txtBearbeiterMail" FontSize="12" IsEnabled="False" Width="150" Margin="62,0,0,0"/>
</StackPanel>
<StackPanel x:Name="pnlBestelldatum" Grid.Column="0" Grid.Row="8" Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Name="tbBestelldatum" FontSize="14" FontWeight="Bold" Text="Best.-Datum"/>
<DatePicker x:Name="calBestelldatum" FontSize="12" Width="200" Margin="19,0,0,0" IsTodayHighlighted="true"/>
</StackPanel>
<StackPanel x:Name="pnlRightGap2" Grid.Column="1" Grid.Row="9" Margin="0,10,0,0" Orientation="Horizontal">
</StackPanel>
<StackPanel x:Name="pnlRightGap3" Grid.Column="1" Grid.Row="10" Margin="0,10,0,0" Orientation="Horizontal">
</StackPanel>
<StackPanel x:Name="pnlHinweis" Grid.Column="1" Grid.Row="11" Orientation="Vertical">
<TextBlock x:Name="tbHinweis" FontSize="12">
<Run Text=" Bitte geben sie auf ihren Dokumenten immer folgende Informationen an:
• Name des Bauvorhabens
• HV-Nummer und/oder Kostenstelle
• Name des Bestellers
• Abholer (nur bei Abholungen)
Entsprechende Angaben sind in dieser Bestellung fett/kursiv markiert. "/>
<Run FontFamily="Verdana" FontSize="11" Text="Rechnungen mit unvollständigen Angaben müssen wir ab dem 01.12.2013 ungebucht an sie zurücksenden. "/>
</TextBlock>
</StackPanel>
<StackPanel x:Name="pnlProjektleiter" Grid.Column="0" Grid.Row="14" Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Name="tbProjektleiter" FontSize="14" FontWeight="Bold" Text="Projektleiter"/>
<TextBox x:Name="txtProjektleiter" Text="{Binding Projektleiter, Mode=OneWay}" FontSize="12" IsEnabled="False" Width="225" Margin="50,0,0,0" AcceptsReturn="False"/>
</StackPanel>
</StackPanel>
<!-- unten -->
<DataGrid x:Name="dgArtikel" ItemsSource="{Binding Artikel}" Margin="5" Grid.Row="1" Grid.ColumnSpan="2"
SelectionMode="Single" SelectionUnit="Cell" IsReadOnly="False"
CanUserAddRows="True" CanUserDeleteRows="True" AutoGenerateColumns="False"
BorderBrush="Black" BorderThickness="2" RowHeight="30" FontFamily="Arial Narrow" FontSize="18"
LostFocus="DgArtikel_LostFocus" GotFocus="DgArtikel_GotFocus">
<!-- Style Column Headers -->
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Foreground" Value="#FFFFFF"/>
<Setter Property="Background" Value="#DD002C"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="BorderThickness" Value="0,0,1,2"/>
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="FontSize" Value="18"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="Height" Value="30"/>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Header="Pos" Binding="{Binding Pos}"/>
<DataGridTextColumn Header="Artikelbezeichnung" Binding="{Binding Artikelbezeichnung}"/>
<DataGridTextColumn Header="Artikelnummer" Binding="{Binding Artikelnummer}"/>
<DataGridTextColumn Header="Einheit" Binding="{Binding Einheit}"/>
<DataGridTextColumn Header="Menge" Binding="{Binding Menge}"/>
<DataGridTextColumn Header="Einzelpreis" Binding="{Binding Einzelpreis}"/>
<DataGridTextColumn Header="Gesamtpreis" Binding="{Binding Gesamtpreis}"/>
<DataGridComboBoxColumn Header="Anforderungsgrund" x:Name="dgcbAnf" ItemsSource="{Binding Anforderungsgrund}"/>
<DataGridTextColumn Header="Anforderungsnr" Binding="{Binding Anforderungsnr}"/>
<DataGridTextColumn Header="Anforderer" Binding="{Binding Anforderer}"/>
<DataGridTextColumn Header="Bemerkungen" Binding="{Binding Bemerkungen}"/>
</DataGrid.Columns>
</DataGrid>
<Border x:Name="borderBtnArtikel" Grid.Row="2" Grid.Column="0" Margin="25,0,0,0" CornerRadius="10" BorderBrush="Black" BorderThickness="2" Background="PaleVioletRed" HorizontalAlignment="Left">
<Button Name="btnArtikel" Margin="3,0,3,0" Content="Artikel suchen" Height="30" FontWeight="Bold" FontSize="15" Background="PaleVioletRed" Click="BtnArtikel_Click" VerticalAlignment="Top" BorderThickness="0" BorderBrush="PaleVioletRed"></Button>
</Border>
<Border x:Name="borderBtnVorhanden" Grid.Row="2" Grid.Column="0" Margin="0,0,25,0" CornerRadius="10" BorderBrush="Black" BorderThickness="2" Background="Yellow" HorizontalAlignment="Right">
<Button Name="btnVorhanden" Margin="3,0,3,0" Content="Vorhandene Nb Aufrufen" Height="30" FontWeight="Bold" FontSize="15" Background="Yellow" Click="BtnVorhanden_Click" VerticalAlignment="Top" BorderThickness="0" BorderBrush="Yellow"></Button>
</Border>
<Border Grid.Row="2" Grid.Column="1" CornerRadius="10" BorderBrush="Black" BorderThickness="2" Background="Green" Margin="25,0,0,0" HorizontalAlignment="Left">
<Button Name="btnSpeichern" Margin="3,0,3,0" Content="Neue Nb Speichern"
BorderThickness="0" BorderBrush="Green"
Height="30" FontWeight="Bold" FontSize="15"
Background="Green"
VerticalAlignment="Top"
Command="{Binding SaveNb}"
>
</Button>
<!-- Click="BtnSpeichern_Click" -->
</Border>
<Border Grid.Row="2" Grid.Column="1" CornerRadius="10" BorderBrush="Black" BorderThickness="2" Background="Orange" HorizontalAlignment="Right" Margin="0,0,25,0">
<Button Name="btnOutlook" Margin="3,0,3,0" Content="Nb per Outlook versenden" Height="30" BorderThickness="0" BorderBrush="Orange" FontWeight="Bold" FontSize="15" Background="Orange" Click="BtnOutlook_Click"></Button>
</Border>
</Grid>
Как видите,Операция Outlook (оранжевая кнопка) по-прежнему тесно связана в очень плохом дизайне с обработчиком событий BtnOutlook_Click внутри CodeBehind. Поэтому после правильного связывания зеленой кнопки SaveNb с этими четырьмя упомянутыми способами я продолжил бы эту кнопку и другие кнопки, отсоединяя их одну за другой от CodeBehind для лучшего повторного использования и гибкого кода в соответствии со стандартными соглашениями.