Square RadioButton in Silverlight

Hello All,


My project GUI has various screens with Radiobuttons given for user choice. These buttons are graphically circular in design, I thought of changing it to Square just for the sake of making the design look unique. So I did some changes in style and it was done.


Following is the Source code for the change of design from circular to square


Happy Coding :)

Silverlight and MySQL

Hello All,


I would like to share a new aspect in Silverlight. We all know that Silverlight doesn't support ADO.NET. You can not directly call ADO.NET code from SilverLight application but you can call a WCF service. You can convert Dataset into List and just pass it over to Silverlight Application Via WCF.


Here is one way you can use MYSQL with Silverlight.


I have just created a class called City and in the List object of City I have filled all the City Names and binded it with DataGrid.


You can download the source code from Project/Source Code.


Let me know if you find any issues with the Source code.


NOTE: I have not added mysql connection string so first put the connection string in WebConfig file in SilverlightAndMySQL.Services Project.


Happy Coding :)

Sr. No/Row Number for Silverlight 3 DataGrid

Hello All,


Let me first wish you all A Very Happy New Year!!!!


Few days back a query was posted on silverlight forum which says:


"I want to add a column in my datagrid control to show Serial Numbers. I want that column to be Constant i-e i dont want to make that serial number field a part of the objects in the collection binded to the ItemSource property of the Datagrid. On the other hand i would prefer a solution other than ValueConverter. Does datagrid itself gives some kind of support for this?? Or in what way it can be done through handling some event of datagrid in code behind??? "


Though I posted the reply, I was not satisfied with it as it was giving problem when Datagrid has paging.


Here is that reply to post: http://forums.silverlight.net/forums/t/156575.aspx


The problem here was when we give paging to datagrid, on each Page it was re-numbering from 1 instead of continuing with the numbers that ended on the previous page. After spending some time on it I could figure it out how make it work.
Here is the correct way:


Xaml Page:


<StackPanel Orientation="Vertical">
<Data:DataGrid x:Name="dgEmployee" SelectionMode="Single" Margin="5" AutoGenerateColumns="False"

Grid.Row="0" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="False">
<Data:DataGrid.Columns>
<Data:DataGridTemplateColumn Header="Sr. No" Width="90">
<Data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock x:Name="tbID"></TextBlock>
</DataTemplate>
</Data:DataGridTemplateColumn.CellTemplate>
</Data:DataGridTemplateColumn>

<Data:DataGridTextColumn Binding="{Binding FirstName}" Header="FirstName" IsReadOnly="True" Width="90">
</Data:DataGridTextColumn>
<Data:DataGridTextColumn Binding="{Binding LastName}" Header="LastName" IsReadOnly="True" Width="90">
</Data:DataGridTextColumn>
</Data:DataGrid.Columns>
</Data:DataGrid>
<Data:DataPager x:Name="customerPager" PageSize="5" Source="{Binding Path=ItemsSource, ElementName=dgEmployee}"></Data:DataPager>
</StackPanel>


Code Behind:
#region Variables
int PageIndex = 0;

#endregion


#region Page Constructor
public MainPage()
{
        InitializeComponent();
        AttachEventHandlers();
        PagedCollectionView pagedcollectionview = new PagedCollectionView(Employee.GetSampleEmployeeList());
        dgEmployee.ItemsSource = pagedcollectionview;
        dgEmployee.Columns[0].IsReadOnly = true;
}
#endregion


#region Attach Event Handlers Method
void AttachEventHandlers()
{
       dgEmployee.LoadingRow += new EventHandler<DataGridRowEventArgs>(dgEmployee_LoadingRow);
}
#endregion


#region DataGrid Events
void dgEmployee_LoadingRow(object sender, DataGridRowEventArgs e)
{
        DataGridRow dgRow = DataGridRow.GetRowContainingElement(e.Row);
        TextBlock textblock = dgEmployee.Columns[0].GetCellContent(dgRow) as TextBlock;
        if (textblock != null)
        {
                if (e.Row.GetIndex() == 0)
               {
                        textblock.Text = ((customerPager.PageSize * customerPager.PageIndex) + 1).ToString();
                        PageIndex = (customerPager.PageSize * customerPager.PageIndex) + 1;
               }
               else
                        textblock.Text = (++PageIndex).ToString();
        }
}
#endregion


Comments are always welcome.


You can download SourceCode.


Happy Coding :)