button event from dynamic column

3 posts, 0 answers
  1. Azim
    Azim avatar
    2 posts
    Member since:
    Sep 2014

    Posted 01 Dec 2014 Link to this post

    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. Azim
    Azim avatar
    2 posts
    Member since:
    Sep 2014

    Posted 01 Dec 2014 in reply to Azim Link to this post

    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");
           }
  3. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 02 Dec 2014 Link to this post

    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.

     
Back to Top