Click here to Skip to main content
12,457,770 members (37,685 online)
Rate this:
 
Please Sign up or sign in to vote.
Hi All,

I am working on Silverlight 3.0 with MVVM . In this,I have bind Button "Command" Property as below -
1. Bind Command
<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>

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<bool> canExecute;
        private Action executeAction;
        public event EventHandler CanExecuteChanged; 
        public RelayCommand(Action executeAction,
            Func<bool> 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();
        }
    }

XAMLParseException Occurred
AG_E_PARSER_BAD_PROPERTY_VALUE [Line: 43 Position: 51]


Can you please suggest me.
Posted 3-Oct-12 19:29pm
Updated 3-Oct-12 22:34pm
DaveAuld187.6K
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100