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
375
LabelPresenter not found on XamDataGrid Load Event
posted

Hello Infragistics team,

I am facing issue while getting childrens of type LabelPresenter in XamDataGrid. If I bound my grid to SampleData(using BindToSampleData="True" attribute) then i can get the LabelPresenter type childrens, but in case of binding it to explicit datasource the LabelPresenter childrens are not found in XamDataGrid.

In my sample project I have created a behavior (XamDataGridBehavior) which attach the SizeChanged event to every LabelPresetner. I want to call sizechanged event on every time the size of column changes. Kindly could you tell me what the problem is when I bind grid with explicit datasource?

Thanks

Regards

XamDataGridColumnResizingIssue.rar
  • 16495
    Verified Answer
    Offline posted

    Hello,

    Thank you for the attached project.

    I have investigated your issue and it seems that the LabelPresenters are not created in the VisualTree yet and this is why they are not fond.  I believe that you can avoid this, if you put the logic where access the LabelPresenters in a BeginInvoke method of Dispatcher in order to delay the executing of the code like this:


    void AssociatedObject_Loaded(object sender, System.Windows.RoutedEventArgs e)
    { //In case of BindToSampleData labelpresenters are fetched. In for datasource there is no labelpresenters found.
         Dispatcher.BeginInvoke(new Action(() =>
        {
            var  lablePresenters = (IEnumerable<LabelPresenter>)(AssociatedObject as XamDataGrid).FindChildren<LabelPresenter>(true);
            foreach (LabelPresenter ele in lablePresenters)
            {
                ele.SizeChanged += labelPresenter_SizeChanged;
            }

        }), System.Windows.Threading.DispatcherPriority.Background);
    }


    Please let me know if you require any further assistance regarding this matter.

    Sincerely,
    Zhivko
    Entry Level Software Developer