ParameterizedCallMethodAction - SaneDevelopment/WPF-Controls GitHub Wiki
ParameterizedCallMethodAction
is handy extension for Microsoft.Expression.Interactivity.Core.CallMethodAction
, a data behavior from Blend SDK for WPF
.
It's absolutely the same, but provides up to seven additional parameters for the action.
Suppose we have dialog window for changing password in database. Is contains three text boxes: for old password, new password and confirmation of new password.
When press on OK
button calls method SqliteEventManager.OnChangePassword
.
public class SqliteEventManager : Freezable
{
public void OnChangePassword(object sender, EventArgs e)
{
var parArgs = e as ParameterizedEventArgs;
var dbModeViewModel = parArgs.Parameter as IProviderSpecificDbModeViewModel;
var viewModel = parArgs.Parameter2 as IDatabaseActionWorkflowManager;
var oldPwdBox = parArgs.Parameter3 as PasswordBox;
var newPwd1Box = parArgs.Parameter4 as PasswordBox;
var newPwd2Box = parArgs.Parameter5 as PasswordBox;
var sqliteSettings = dbModeViewModel.ProviderSpecificDataBaseSettings as SqliteDbSettingsViewModel;
// do change password and clear password boxes
}
}
...
<eventManagers:SqliteEventManager x:Key="SqliteEventManager"/>
...
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0"
Grid.Column="0"
Content="Old password:"
Target="{Binding ElementName=TxtOldPassword}"
HorizontalAlignment="Right"
Margin="5"/>
<PasswordBox Grid.Row="0"
Grid.Column="1"
x:Name="TxtOldPassword"
HorizontalAlignment="Left"
MinWidth="300"
MaxWidth="500"
Margin="5"/>
<Label Grid.Row="1"
Grid.Column="0"
Content="New password:"
Target="{Binding ElementName=TxtNew1Password}"
HorizontalAlignment="Right"
Margin="5"/>
<PasswordBox Grid.Row="1"
Grid.Column="1"
x:Name="TxtNew1Password"
HorizontalAlignment="Left"
MinWidth="300"
MaxWidth="500"
Margin="5"/>
<Label Grid.Row="2"
Grid.Column="0"
Content="Confirm new password:"
Target="{Binding ElementName=TxtNew2Password}"
HorizontalAlignment="Right"
Margin="5"/>
<PasswordBox Grid.Row="2"
Grid.Column="1"
x:Name="TxtNew2Password"
HorizontalAlignment="Left"
MinWidth="300"
MaxWidth="500"
Margin="5"/>
<StackPanel Grid.Row="3"
Grid.ColumnSpan="2"
Orientation="Horizontal"
Margin="10">
<Button Content="OK" Margin="5" MinWidth="70">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<saneDev:ParameterizedCallMethodAction
TargetObject="{StaticResource SqliteEventManager}"
MethodName="OnChangePassword"
Parameter="{Binding}"
Parameter2="{Binding Path=DataContext, RelativeSource={RelativeSource AncestorType=Window}}"
Parameter3="{Binding ElementName=TxtOldPassword}"
Parameter4="{Binding ElementName=TxtNew1Password}"
Parameter5="{Binding ElementName=TxtNew2Password}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</Grid>
...