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 :)

Run Class in Silverlight

Hello All,


While using Silverlight most of you must have come across a situation wherein you have to show the text like this:


This is my text.


One question comes into mind is "How to do this in Silverlight" as we can do this in HTML using span tag.


The Run class which is inherited from the abstract System.Windows.Documents.Inline.


Run Class has following Properties:
  1. FontFamily
  2. FontSize
  3. FontStyle
  4. FontWeight
  5. TextDecorations
and some more.


In Xaml code it was very easy to do it.


Example:


<TextBlock x:Name="tb">
     <Run FontWeight="Bold">This</Run>
     <Run Foreground="Blue">is my</Run>
     <Run ForeStyle="Italic">Text.</Run>
</TextBlock>


Output:


This is my Text.


Similarly, we can do it in code behind:


tb.Inlines.Add(new Run() { Text="This ", FontSize=12, FontWeight = FontWeights.Bold });
tb.Inlines.Add(new Run() { Text="is my ", FontSize=12, Foreground = new SolidColorBrush(Colors.Blue});
tb.Inlines.Add(new Run() { Text="Text.", FontSize=12, FontStyle = FontStyles.Italic });


and thats all you have to do.


Happy coding :)