This is a migrated thread and some comments may be shown as answers.

button event from dynamic column

2 Answers 90 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Azim
Top achievements
Rank 1
Azim asked on 01 Dec 2014, 10:01 AM
I need 
I changed code in "Binding column from view model" (SDK samples browser).
MyDataContext.cs:
                    
 public ObservableCollection<GridViewColumn> Columns<br>        {<br>            get<br>            {<br>                if (columns == null)<br>                {<br>                    columns = new ObservableCollection<GridViewColumn>();<br>                    columns.Add(new GridViewDataColumn() { DataMemberBinding = new System.Windows.Data.Binding("ID") });<br><br><br>                    FrameworkElementFactory fe = new FrameworkElementFactory(typeof(System.Windows.Controls.Button));<br>                    fe.AddHandler(System.Windows.Controls.Button.ClickEvent, new RoutedEventHandler(OnClick));<br>                    fe.SetValue(System.Windows.Controls.Button.ContentProperty, "Button");<br>                    DataTemplate dt2 = new DataTemplate();<br>                    dt2.VisualTree = fe;<br>                    dt2.Seal();<br><br>                    GridViewDataColumn col = new GridViewDataColumn() { DataMemberBinding = new System.Windows.Data.Binding("Name") };<br>                    col.CellTemplate = dt2;<br><br>                    columns.Add(col);<br>                }<br>                return columns;<br>            }<br>        }<br><br>        private void OnClick(object sender, RoutedEventArgs e)<br>        {<br>            MessageBox.Show("The button was clicled");<br>        }
When Button clicked nothing happend.
How to get Clicked Event?

2 Answers, 1 is accepted

Sort by
0
Azim
Top achievements
Rank 1
answered on 01 Dec 2014, 10:05 AM
public ObservableCollection<GridViewColumn> Columns
       {
           get
           {
               if (columns == null)
               {
                   columns = new ObservableCollection<GridViewColumn>();
                   columns.Add(new GridViewDataColumn() { DataMemberBinding = new System.Windows.Data.Binding("ID") });
 
 
                   FrameworkElementFactory fe = new FrameworkElementFactory(typeof(System.Windows.Controls.Button));
                   fe.AddHandler(System.Windows.Controls.Button.ClickEvent, new RoutedEventHandler(OnClick));
                   fe.SetValue(System.Windows.Controls.Button.ContentProperty, "Button");
                   DataTemplate dt2 = new DataTemplate();
                   dt2.VisualTree = fe;
                   dt2.Seal();
 
                   GridViewDataColumn col = new GridViewDataColumn() { DataMemberBinding = new System.Windows.Data.Binding("Name") };
                   col.CellTemplate = dt2;
 
                   columns.Add(col);
               }
               return columns;
           }
       }
 
       private void OnClick(object sender, RoutedEventArgs e)
       {
           MessageBox.Show("The button was clicled");
       }
0
Dimitrina
Telerik team
answered on 02 Dec 2014, 09:49 AM
Hi,

You can refer to the FrameworkElementFactory.AddHandler not working topic where the same question has already been discussed.

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Azim
Top achievements
Rank 1
Answers by
Azim
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or