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
215
Custom XamGrid control
posted

Hello

I need to create a custom control using XamGrid. Could you suggest a code sample how do it?

I need custom control with a textbox and XamGrid.

http://prntscr.com/g6ba9z

And I when I will use this control I want to define columns in a place where it using.

And I stuck with a problem that I can't find a way how to use TemplateBinding for XamGrid.Columns. Do you have any idea?

Parents
No Data
Reply
  • 34810
    Offline posted

    Hello Andrey,

    In order to achieve your requirement in this case, I would recommend using a UserControl. In doing so, you could set up the visual tree of that particular control to have a TextBox and a XamGrid inside, so that when you use it, these elements would show up together.

    If you give the XamGrid in your UserControl an x:Name, you can access it using that name. For example, you could do something like the following when using the UserControl programmatically:

    MyUserControl control = new MyUserControl();
    XamGrid grid = control.theGrid as XamGrid;

    From there, you could manually add the columns to the XamGrid.Columns collection.

    I am rather unsure why you are trying to use a TemplateBinding for the Columns collection of the XamGrid, but this will not work at the moment, as the XamGrid.Columns collection is not a DependencyProperty, and as such, cannot be bound. Perhaps you could create a derivation of the XamGrid in which you add a DependencyProperty that talks to the Columns collection of the underlying XamGrid when it is changed?

    I have attached a sample project to demonstrate the UserControl approach mentioned above. I hope this helps.

    Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer

    XamGridCustomControl.zip
Children