Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
825
HeaderPrefixArea MouseLeftButtonDown Event with a xamDataGrid in code behind
posted

Hi,

i'm trying to implement a MouseLeftButtonDown Event in the HeaderPrefixArea in a code behind xamDataGrid,

but i can't get it work!

Everything works fine if i build a xamDataGrid in XAML and modify the HeaderPrefixAreaStyle in the Resources of the xamDataGrid in XAML.

But if i try to do similar things in an code behind grid, i fail everytime.

I used this article as reference: http://ko.infragistics.com/community/forums/p/67080/339815.aspx#339815

I attached an example project which explains all.

Thanks for your help,

Jochen

xamDataGrid_HeaderPrefixArea.zip
  • 12875
    Verified Answer
    posted

    Hi Jochen, 

    I modified your sample's InitHeaderPrefixArea function adding a ControlTemplate and a textBlock to which I added an event handler. 

    Here's the section of code that I changed:

    public void InitHeaderPrefixArea()

            {

                Style headerPrefixAreaStyle;

            

                ControlTemplate ct = new ControlTemplate(typeof(Infragistics.Windows.DataPresenter.HeaderPrefixArea));

                TextBlock txtblock = new TextBlock();

                txtblock.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(txtblock_PreviewMouseLeftButtonDown);

                FrameworkElementFactory txtblock1 = new FrameworkElementFactory(typeof(TextBlock));

                txtblock1.AddHandler(UIElement.PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(txtblock_PreviewMouseLeftButtonDown));

                ct.VisualTree = txtblock1;    

      

                if (example == Example.Example1)

                {

                    // TEST 1 - failed

                    headerPrefixAreaStyle = new Style(typeof(Infragistics.Windows.DataPresenter.HeaderPrefixArea));

                    headerPrefixAreaStyle.Setters.Add(new Setter(Infragistics.Windows.DataPresenter.HeaderPrefixArea.HorizontalAlignmentProperty, HorizontalAlignment.Center));

                    headerPrefixAreaStyle.Setters.Add(new Setter(Infragistics.Windows.DataPresenter.HeaderPrefixArea.VerticalAlignmentProperty, VerticalAlignment.Center));

                    headerPrefixAreaStyle.Setters.Add(new Setter(Infragistics.Windows.DataPresenter.HeaderPrefixArea.VisibilityProperty, Visibility.Visible));

                    //headerPrefixAreaStyle.Setters.Add(new EventSetter(Infragistics.Windows.DataPresenter.HeaderPrefixArea.PreviewMouseLeftButtonDownEvent, new System.Windows.Input.MouseButtonEventHandler(HeaderPrefixArea_MouseButtonDown)));

                  

                    headerPrefixAreaStyle.Setters.Add(new Setter( TemplateProperty, ct));

     

                }

                Else

     

    When I added the event it generated the following block of code to which I added the message box.

    void txtblock_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)

    {

         MessageBox.Show(" textblock clicked");

    This event fires when I click on the header prefix area of the Example1 layout. 

    Please let me know if you have any questions.