Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7929903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:14:32+00:00 2026-06-03T20:14:32+00:00

I am dynamically creating the columns for a data grid in a User control

  • 0

I am dynamically creating the columns for a data grid in a User control in Silverlight 4 which is working correctly.
The first column of the data grid is a button so I am using the following code to add the DataTemplate for the DataGrid:

DataGridTemplateColumn templateColumn = new DataGridTemplateColumn();
templateColumn.Header = "Search";
StringBuilder sb = new StringBuilder(); 
sb.Append("<DataTemplate ");
sb.Append("xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' ");
sb.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>");
sb.Append("<Button Name='searchBtn' Width='25' Height='20' Click='performFastSearch' >");
sb.Append("<Image Source='http://localhost/SiteAssets/img/Homepage/ribbon_top_right.png'  Stretch='None' />");
sb.Append("</Button>");
sb.Append("</DataTemplate>");

templateColumn.CellTemplate = (DataTemplate)XamlReader.Load(sb.ToString());

The code works if I leave the Click=”performFastSearch” part out but breaks with a ‘crossappdomainmarshaledexception’ when I add it in.

Is this how I should be trying to add the click handler method or should I be using something else?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:14:34+00:00Added an answer on June 3, 2026 at 8:14 pm

    The XAML syntax you are using, where you specify a named method for the Click event only works if the XAML is defined within a user control, in this context, the code generated by Visual Studio will automatically wire-up your click handler. As you are creating your XAML in code, you will have to locate this Button when it is generated and wire up the click handler yourself.

    When each row is rendered, handle the loading event to find the Button then wire-up. This blog post might help you:

        void grid_LoadingRow(object sender, DataGridRowEventArgs e) 
        { 
            var btnCol =  
            m_DataGrid.Columns.FirstOrDefault(
                    c => c.GetValue(FrameworkElement.NameProperty) as string == "m_BtnColumn");
    
            FrameworkElement el = btnCol.GetCellContent(e.Row);
    
            Button btn = el as Button;
    
            if (btn != null) 
            {    
                btn.Click -= new RoutedEventHandler(btn_Click); 
                btn.Click += new RoutedEventHandler(btn_Click); 
            } 
        }
    
    
        void btn_Click(object sender, RoutedEventArgs e) 
        { 
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm creating columns dynamically for a Grid layout in Silverlight (V3.0, C#): LayoutRoot.ColumnDefinitions.Add(new
I am creating tables and column dynamically. First creating tables and then adding columns
I have a WPF ListView control for which I am dynamically creating columns. One
I have found code like this for dynamically creating a Grid and some columns:
I am dynamically creating a RadGrid and adding GridTemplateColumns to it. Those columns have
i am dynamically creating radio using jquery as shown belown. but they value only
I am having a JSP page, where i am dynamically creating a Table data.
I am creating a gridview dynamically with a ButtonField and several BoundFields. ButtonField button
I'm dynamically creating DataGrid columns (based on an event from my ViewModel) and programmatically
am working in windows application with c#.Am creating the listview items dynamically..i want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.