Showing posts with label Silverlight. Show all posts
Showing posts with label Silverlight. Show all posts

Monday, May 17, 2010

How to Dynamically create Silverlight User control.

I have Add a dynamically created Silverlight User control in another Silverlight User Control. I create this control from a XML file data.

Here are the step and necessary Code for reference:

Step-1:
Add the usercontrol as per requirement.
Step-2:
In your MainPage.xml
Add : xmlns:local="clr-namespace:ProjectSample"

< Grid x:Name="LayoutRoot">
< Grid.RowDefinitions>
< RowDefinition Height="550*"/>
< RowDefinition Height="50"/>

< Grid.ColumnDefinitions>
< ColumnDefinition Width="Auto"/>

< Grid Grid.Row="0" Grid.Column="0">
< controlsToolkit:WrapPanel Orientation="Vertical" x:Name="AddressPanel" HorizontalAlignment="Left"/>
< Button x:Name="Save" Grid.Row="1" Grid.Column="0" Click="Save_Click" Content="Save" Height="22" Width="60" HorizontalAlignment="Center" VerticalAlignment="Top" TabIndex="8" Cursor="Hand"/>



Step-3:
In your MainPage.xml.cs

ucAddress ucObj;
for (int i = 0; i < 5; i++)
{
ucObj = new ucAddress();
ucObj.Name = "ucName" + i;
AddressPanel.Children.Add(ucObj);
}

Step-3:
Retriving the data from usercontrol and inserting it.
private void Save_Click(object sender, RoutedEventArgs e)
{
User usr;

for (int i = 0; i < 5; i++)
{
ucObj = (ucAddress)LayoutRoot.FindName("ucName" + i);
usr = new User();
usr.Email = "test@t.com";
usr.Firstname = ucObj.FirstNameData.Text;
usr.Lastname = ucObj.LastNameData.Text;
usr.Username = ucObj.CityData.SelectionBoxItem.ToString();
usr.Password = "pa55w0rd!";
usr.Sex = "M";
_RegDContext.Users.Add(usr);
}

_submitOp = _RegDContext.SubmitChanges();
_submitOp.Completed +=new EventHandler(_submitOp_Completed);

}

Hope this will be useful & your comments are mostly welcome.

Friday, April 16, 2010

Sorting in datagrid in Silverlight for custom columns - SortMemberPath

SortMemberPath :

Sometimes the property that your column is bound to is not always the one that you want it to sort by.
SortMemberPath is on DataGridColumn, you can use this beyond just template columns and can actually have a column bound to one property, but sort based on another property.

<data:datagridtemplatecolumn header="Start Date" width="110" sortmemberpath="RoomEffectiveOn"></data:datagridtemplatecolumn>

Tuesday, April 13, 2010

Silverlight buttons are not working inside an IFrame in firefox 3.6


Silverlight control was hosted on a page, and the page was being called in an IFrame in another application. In this case, the hyperlinks and buttons in Silverlight area inside IFrame was not working in firefox 3.6 although it was working fine in Internet Explorer,

simply changed the windowless property of Object tag to false, and the hyperlinks and buttons in Silverlight inside IFrame will working properly.