On WPF form I have a hyperlink that when clicked is supposed aggregate some data in database before redirecting to internal web page.
Currently XAML looks following:
<Hyperlink RequestNavigate="Hyperlink_RequestNavigate" IsEnabled="{Binding CanTakePayment}">
Launch Payments Portal
</Hyperlink>
to do the db stuff Hyperlink_RequestNavigate method is used, that resides in View.xaml.cs
It looks something like:
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
var transactionReference = GetToken(100M, "13215", "product");
var url = string.Format("{0}New?transactionReference={1}", Settings.Default.PaymentUrlWebsite, transactionReference);
e.Handled = true;
}
I don't like this mechanism being here and would prefer to move it to View model.
What I tried to do is add to ViewModel property
public ICommand NavigateToTakePayment
{
get { return _navigateToTakePayment; }
set { _navigateToTakePayment = value; }
}
and in XAML change binding to
<Hyperlink RequestNavigate="{Binding Path=NavigateToTakePayment}" IsEnabled="{Binding CanTakePayment}">
Launch Payments Portal
</Hyperlink>
but it started giving me cast exceptions.
What is most appropriate way to move this mechanism from View to ViewModel?