Home Forums WPF controls Xceed DataGrid for WPF Dynamicaly loaded User Control Databind from Code Behind

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #22693 |

    If I have a User Control that is dynamically loaded:

    CtrlUsers ctrlUsers = new CtrlUsers();
    GridControl.Children.Add(ctrlUsers);

    GridControl is the Microsoft WPF control and CtrlUsers contains the Xceed WPF DataGrid.

    This method that returns a list of test users resides on the MainForm.xaml code behind, the same form CtrlUsers is dynamically loaded from.
    private List<PersonDto> GetUsers()
    {
    List<PersonDto> personList = new List<PersonDto>();
    for(int i=0;i<10;i++)
    {
    PersonDto person = new PersonDto();
    person.FirstName = “Test”;
    person.LastName = “User” + i;
    personList.Add(person);
    }
    return personList;
    }

    What is the best way to bind the Exceed WPF DataGrid inside the CtrlUsers User Control from GetUsers method?

    Thanks for any help
    Brian K. Williams

    Imported from legacy forums. Posted by Brian (had 1845 views)

    Xceed Support
    Member
    Post count: 5658

    I would investigate the use of ObjectDataProvider to retrieve the data from your methods…

    Other than that, I can also suggest transforming the method into a property and then use a Binding with a FindAncestor RelativeSource ( AncestorType would be your MainForm`s type).

    Imported from legacy forums. Posted by Marcus [Xceed] (had 2966 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.