Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

How to bind click event for button to the Inside DataGr... RSS

2 replies

Last post Nov 15, 2008 09:36 AM by preishuber

(0)
  • shan_aspdotnet

    shan_aspdotnet

    Member

    16 Points

    61 Posts

    How to bind click event for button to the Inside DataGrid's Button

    Nov 15, 2008 04:31 AM | LINK

    I have tried this

    <data:DataGrid x:Name="dgSample" AutoGenerateColumns="False">
                    <data:DataGrid.Columns>
                        <data:DataGridTemplateColumn Width="100">
                            <data:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Button Content="{Binding Content}" Click="{Binding Click}" ></Button>
                                </DataTemplate>
                            </data:DataGridTemplateColumn.CellTemplate>
                        </data:DataGridTemplateColumn>
                    </data:DataGrid.Columns>
                </data:DataGrid>

                Button btnTemp = new Button();
                btnTemp.Content = "Hello";
                btnTemp.Click += new RoutedEventHandler(btnTemp_Click);
                List<Button> lstBtn = new List<Button>();
                lstBtn.Add(btnTemp);
                dgSample.ItemsSource = lstBtn;

    But it gives me error

     Error        1        The "ValidateXaml" task failed unexpectedly.

    System.InvalidOperationException: Stack empty.

       at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)

       at System.Collections.Generic.Stack`1.Pop()

       at MS.MarkupCompiler.ValidationPass.ValidateXaml(String fileName, Assembly[] assemblies, Assembly callingAssembly, TaskLoggingHelper log, Boolean shouldThrow)

       at Microsoft.Silverlight.Build.Tasks.ValidateXaml.XamlValidator.Execute()

       at Microsoft.Silverlight.Build.Tasks.ValidateXaml.XamlValidator.Execute()

       at Microsoft.Silverlight.Build.Tasks.ValidateXaml.Execute()

       at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult)

     

    Is there another way to bind the Button with DataGrid ?

    Plz Help.

    Shan
    Asp.Net, Silverlight
  • preishuber

    preishuber

    Contributor

    3572 Points

    658 Posts

    Re: How to bind click event for button to the Inside DataGrid's Button

    Nov 15, 2008 08:52 AM | LINK

    why do you try to bind the click event? (guess not possible)

    and not                  <Button Content="{Binding Content}" Click="Button_click" ></Button>
                

    -Hannes

    http://www.ppedv.de
  • preishuber

    preishuber

    Contributor

    3572 Points

    658 Posts

    Re: How to bind click event for button to the Inside DataGrid's Button

    Nov 15, 2008 09:36 AM | LINK

    i have added a small article to my blog which describes the details

    http://weblogs.asp.net/hpreishuber/

    -Hannes

    http://www.ppedv.de