Whitespace is not allowed after end of Markup Extension -- Silverlight Compile Time Error

Today while working on one of my Silverlight Project, I did some changes in the user control and built the Project and all of sudden I got the compile time error saying:
Whitespace is not allowed after end of Markup Extension.

I tried finding where exactly the whitespace has come. Initially I thought while giving name to any of control I gave white space in it but was wrong and then I could find what was the issue. Check the image you will understand what mistake I did and I thought of writting this blog.

Happy Coding!!!!

How to Align Text in DataGrid Cell in Xaml and in Code Behind

Hello,

While answering a query on silverlight forum, I thought of writing this article.
Quoting the question as:

DataGridTextColumn textColumn = new DataGridTextColumn();
textColumn.Header = "Result";
textColumn.Binding = new Binding("Result");
dataGrid1.Columns.Add(textColumn);

how i can set RESULT alignment right?

Here is what you have to do, I will show you this in both ways like doing it in Xaml Page and doing it in code behind.

First add the Style in your User Control Resource:

<UserControl.Resources>
      <Style x:Key="AlignRight" TargetType="Data:DataGridCell">
          <Setter Property="HorizontalContentAlignment" Value="Right" />
     </Style>
</UserControl.Resources>
 
I'm doing this for Right Align but you can change it according to your requirement.
 
Next, how to do this in Xaml Page? Its very simple, apply this style to whichever column you want, like this:
 
<Data:DataGridTextColumn Header="Amount" Width="90" Binding="{Binding Amount}" IsReadOnly="True" CellStyle="{StaticResource AlignRight}"></Data:DataGridTextColumn>
 
Now how to do this in code behind:
 
DataGridTextColumn textColumn = new DataGridTextColumn();
textColumn.Header = "Result";
textColumn.Binding = new Binding("Result");
textColumn.CellStyle = Resources["AlignRight"] as Style;
dataGrid1.Columns.Add(textColumn);

Comments are always welcome.

Happy Coding :)

ComboBox inside Silverlight DataGrid

Hello All,

How to implement ComboBox inside Silverlight DataGrid. Here I have uploaded a sample Project which would help you all.

Source Code

Happy Coding :)

How to Bind Silverlight ComboBox with Enum

Hello All,

Binding Silverlight ComboBox with Enum. Suppose we have Enum like this:

public enum Schedule
{
     Day = 1,
     Week = 7,
     Month = 30,
     Year = 365
}
 
then how are we going to bind it with ComboBox. Here is the code:

// Returns all the Enums

public static T[] GetEnumValues()
{
       var type = typeof(T);
       if (!type.IsEnum)
       throw new ArgumentException("Type '" + type.Name + "' is not an enum");
       return (from field in type.GetFields()
       where field.IsLiteral
       select (T)field.GetValue(type)).ToArray();
}
 
ComboBox cbo = sender as ComboBox;
var enums = GetEnumValues();
cbo.ItemsSource = enums;

Happy Coding :)

How to find the last identity value inserted in MYSQL

Hello All,


If you are writing an Insert query and what to find out the last inserted ID then here is what you execute to get the last inserted ID.

DECLARE iID INT;
-- Your Insert query goes here and iID will have your last Inserted ID.
SELECT LAST_INSERT_ID() INTO iID;

Hope that helps.

Bullets For Silverlight ListBox

Here is what the output looks like:












While answering a query on silverlight forum, I thought of writing this blog.

Quoting the question as:
How do I add Bullet Points in SilverLight 4.0?
I tried the <ul> </ul> HTML code and it doesn't work. Is there a special code in SilverLight for Bullet Points?

Here is what you can try:

Xaml Code:

<ListBox x:Name="lbMyBullet" VerticalAlignment="Stretch" Margin="5,2,2,2" Height="150" HorizontalAlignment="Stretch" Width="240">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="images/small-arrowblue.png" VerticalAlignment="Center" Height="9" Width="7"></Image>
<TextBlock x:Name="myBulletText" Margin="5,2,0,0" VerticalAlignment="Top" Text="{Binding Path=Name}" ToolTipService.ToolTip="{Binding Path=Name}"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

In Code Behind:
 
public class Employee
{
public int ID { get; set; }
public string Name { get; set; }
}

ObservableCollection employee = new ObservableCollection();
employee.Add(new Employee() { ID = 1, Name = "Nimish"});
employee.Add(new Employee() { ID = 2, Name = "Vikas"});
employee.Add(new Employee() { ID = 3, Name = "Pooja"});
employee.Add(new Employee() { ID = 4, Name = "Maya"});
employee.Add(new Employee() { ID = 5, Name = "Kiran"});
employee.Add(new Employee() { ID = 6, Name = "Pragati"});
employee.Add(new Employee() { ID = 7, Name = "Lalit"});
employee.Add(new Employee() { ID = 8, Name = "Neha"});
employee.Add(new Employee() { ID = 9, Name = "Sachin"});
employee.Add(new Employee() { ID = 10, Name = "Ishita"});

lbMyBullet.ItemsSource = employee;

You have to just change the image path.

Happy coding :)