Click here to Skip to main content
15,895,797 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

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

C#
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 -
C++
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();
        }
    }

<however above="" code="" is="" not="" working="" and="" i="" getting="" the="" following="" error="" on="" my="" xaml="" page="" mode="hold">
XAMLParseException Occurred
AG_E_PARSER_BAD_PROPERTY_VALUE [Line: 43 Position: 51]


Can you please suggest me.
Posted
Updated 3-Oct-12 22:34pm
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900