Public classsendcommand:icommand{ Public voidExecute (Objectparameter) { varLabels = ((Object[]) parameter). Oftype<label>(); } Public BOOLCanExecute (Objectparameter) { return true; } Public EventEventHandler canexecutechanged =Delegate {};} Public Partial classmainwindow:window{ PublicMainWindow () {InitializeComponent (); DataContext= This; SendCommand=NewSendCommand (); } PublicICommand SendCommand {Get;Set; }} Public classpassthroughconverter:imultivalueconverter{ Public ObjectConvert (Object[] values, Type targetType,Objectparameter, CultureInfo culture) { returnvalues. ToArray (); } Public Object[] Convertback (ObjectValue, type[] targettypes,Objectparameter, CultureInfo culture) { Throw Newnotimplementedexception (); }}
<window x:class="Wpfapplication5.mainwindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="Http://schemas.microsoft.com/winfx/2006/xaml"xmlns:wpfapplication5="Clr-namespace:wpfapplication5"Title="MainWindow"height=" -"Width="525"> <Window.Resources> <wpfapplication5:passthroughconverter x:key="Passthroughconverter"/> </Window.Resources> <Grid> <StackPanel> <label name="Greeting">Hello</Label> <label name="Farewell">Goodbye</Label> <button command="{Binding SendCommand}">Hit me<Button.CommandParameter> <multibinding converter="{StaticResource Passthroughconverter}"> <binding path="."Elementname="Greeting"></Binding> <binding path="."Elementname="Farewell"></Binding> </MultiBinding> </Button.CommandParameter> </b Utton> </StackPanel> </Grid></Window>
Wpf–pass multiple parameters to a Command