How to use same usercontrol multiple time in the silverlight
-
Hi, I am working on a silverlight application. In this I need to place usercontrols on a canvas in the Page.xaml page dynamically at run time. Later I need to set the data values for the datagrid on these user controls from the Page.xaml itself. I want to set different data for different user controls. How can i differentiate these user controls from one another and set differnt data to their datagrid from Page.xaml itself. please reply me if u have any idea to solve this. Thanks in advance
-
Hi, I am working on a silverlight application. In this I need to place usercontrols on a canvas in the Page.xaml page dynamically at run time. Later I need to set the data values for the datagrid on these user controls from the Page.xaml itself. I want to set different data for different user controls. How can i differentiate these user controls from one another and set differnt data to their datagrid from Page.xaml itself. please reply me if u have any idea to solve this. Thanks in advance
There are a couple of ways to do this; it just depends on whether or not you are using pure databinding and MVVM. If you are using MVVM and pure databinding, then there's very little that you need to do because the View/ViewModel integration will take care of the hard work for you. If you aren't, then you can assign a name to each control when you assign it using the
x:Name
property, e.g.x:Name="myUserControl1"
(this is if you add it into the XAML). If you add it using code behind, you just assign the name to theName
property."WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Hi, I am working on a silverlight application. In this I need to place usercontrols on a canvas in the Page.xaml page dynamically at run time. Later I need to set the data values for the datagrid on these user controls from the Page.xaml itself. I want to set different data for different user controls. How can i differentiate these user controls from one another and set differnt data to their datagrid from Page.xaml itself. please reply me if u have any idea to solve this. Thanks in advance
Either you are instantiating the objects yourself, and can take them with x:Name and have your own reference, or you are using them in a template in the DataGrid. If you are using them in a template, you can hook into the Loaded event and do something with them. For example, you might do this:
<DataGrid>...<u:MyControl Loaded="MyControl_Loaded".../>...</DataGrid>
In the
MyControl_Loaded
you can then take the event arguments and do something with the control, either processing, passing it into a controller, etc.Jeremy Likness Latest Article: Whats in Your Collection? Part 1 of 3: Interfaces Blog: C#er : IMage