Hi All, I am working on Silverlight 3.0 with MVVM . In this,I have bind Button "Command" Property as below - 1. Bind Command
Collapse | Copy Code
<Button x:Name="Submit" Content="Submit" ClickMode="Release" Grid.Row="4" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<!--<si:CallDataMethod Method="TestCompany" Target="{Binding SubmitCommand}"/>-->
<si:InvokeDataCommand Command="TestCompany.SubmitCommand" ></si:InvokeDataCommand>
<!--<si:ShowMessageBox Caption="Thank you"
Message="Thanks for trying the Example"
MessageBoxButton="OK"/>
<si:SetProperty TargetName="t21" PropertyName="Background" Value="PaleGoldenrod"/>-->
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
2. View Module - private ICommand _SubmitCommand;
public ICommand SubmitCommand
{
get
if (_SubmitCommand == null)
_SubmitCommand = new RelayCommand(InsertData);
}
return _SubmitCommand;
int i = 0;
void InsertData()
Proxy.InsertCompanyCompleted += new EventHandler<InsertCompanyCompletedEventArgs>(Proxy_InsertCompanyData);
ServiceReference1.Company C = new ServiceReference1.Company()
CompanyID = CompanyID,
CompanyName = CompanyID,
};
Proxy.InsertCompanyAsync(C);
if (i == 1)
MessageBox.Show("Data Inserted Successfully");
// void Proxy_InsertCompanyData(object sender,InsertCompanyCompletedEventArgs e)
void Proxy_InsertCompanyData(object sender, ServiceReference1.InsertCompanyCompletedEventArgs e)
if (e.Error == null)
i = e.Result;
3- There is one more Class Name is Relay Command as below - public class RelayCommand:ICommand { private Func canExecute; private Action executeAction; public event EventHandler CanExecuteChanged; public RelayCommand(Action executeAction, Func canExecute) { this.executeAction = executeAction; this.canExecute = canExecute; } public RelayCommand(Action executeAction) { this.executeAction = executeAction; this.canExecute = () => true; } public void RaiseCanExecuteChanged() { if (CanExecuteChanged != null) { CanExecuteChanged(this, EventArgs.Empty); } } public bool CanExecute(object parameter) { return canExecute == null ? true : canExecute(); } public void Execute(object parameter) { executeAction(); } } However above code is not working and i getting the following error on InitializeComponent()of my xaml page - XAMLParseException Occurred AG_E_PARSER_BAD_PROPERTY_VALUE [Line: 43 Position: 51] Can you plz suggest me.