VIBlend

How to bind the VIBlend DataGrid for Silverlight and WPF to Indexed properties?

by viblend 3. September 2010 19:48

In order to bind the VIBlend DataGrid to indexed properties, you need to do the following:

1. Create DataTemplates that are bound to indexed properties.

        <DataTemplate x:Key="LastNameCellTemplate">
            <Grid>
                <TextBlock Text="{Binding [LastName], Mode=OneWay}"/>
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="FirstNameCellTemplate">
            <Grid>
                <TextBlock Text="{Binding [FirstName], Mode=OneWay}"/>
            </Grid>
        </DataTemplate>

2. Create a new DataGrid instance. Set the CellDataTemplate property of the DataGrid’s BoundFields to point to the DataTemplates.

        <viblend:DataGrid x:Name="dataGrid" Width="400" Height="280" AutoGenerateColumns="True">
            <viblend:DataGrid.BoundFields>
                <viblend:BoundField Text="FirstName" Width="150" CellDataTemplate="{StaticResource FirstNameCellTemplate}"/>
                <viblend:BoundField Text="LastName" Width="150" CellDataTemplate="{StaticResource LastNameCellTemplate}"/>
            </viblend:DataGrid.BoundFields>
        </viblend:DataGrid>

3.  Create a new class that will represent a single record of the DataGrid.

CSharp

public class Person : INotifyPropertyChanged
{   
    public Person()
    {
    }

    private Dictionary<string, object> data = new Dictionary<string, object>();

    public object this[string key]
    {
        get
        {
            if (!data.ContainsKey(key))
            {
                data[key] = null;
            }
            return data[key];
        }
        set
        {
            data[key] = value;
            if (this.PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(""));
            }
        }
    }

    public IEnumerable<string> Keys
    {
        get
        {
            return data.Keys;
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
}

VB .NET

Public Class Person
    Implements INotifyPropertyChanged
    Public Sub New()
    End Sub

    Private data As Dictionary(Of String, Object) = New Dictionary(Of String, Object)()

    Default Public Property Item(ByVal key As String) As Object
        Get
            If (Not data.ContainsKey(key)) Then
                data(key) = Nothing
            End If
            Return data(key)
        End Get
        Set(ByVal value As Object)
            data(key) = value
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(""))
        End Set
    End Property

    Public ReadOnly Property Keys() As IEnumerable(Of String)
        Get
            Return data.Keys
        End Get
    End Property

    Public Event PropertyChanged As PropertyChangedEventHandler
End Class

4.  Create a new generic List of Person objects and set the ItemsSource property of the DataGrid, in order to bind it to the list.

CSharp

       List<Person> listOfPersons = new List<Person>();
       for (int i = 0; i < 10; i++)
       {
           Person person = new Person();
           person["FirstName"] = "FirstName" + i;
           person["LastName"] = "LastName" + i;
           listOfPersons.Add(person);
       }
       this.dataGrid.ItemsSource = listOfPersons;

VB .NET

      Dim listOfPersons As List(Of Person) = New List(Of Person)()
      For i As Integer = 0 To 9
         Dim person As New Person()
         person("FirstName") = "FirstName" & i
         person("LastName") = "LastName" & i
         listOfPersons.Add(person)
      Next i
      Me.dataGrid.ItemsSource = listOfPersons

VIBlend Controls for Silverlight ver. 2.6 - Released

by viblend 21. June 2010 20:37

VIBlend is pleased to announce the immediate availability of VIBlend Controls for Silverlight ver. 2.6. The new version includes several important updates to the company's Silverlight suite.

 Highlights of the new features and improvements in the new version are:

  • Visual Studio 2010 toolbox integration
  • Right Click support in DataGrid
  • DataGrid sorting and filtering using a Context Menu
  • DataGrid performance optimizations
  • Improved DataGrid Office2010 themes
  • Turned off DataGrid deferred scrolling feature by default.
  • Fixed a design time issue in the Menu control.
  • Fixed a design time issue in the TreeView control.
  • Fixed a Stretch alignment issue in the DataGrid control.

See our Silverlight Controls Live Demo and Download a free trial today.

Currently rated 4.7 by 3 people

  • Currently 4.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

Silverlight | Silverlight Controls

VIBlend Controls for Silverlight 4.0 - Released

by viblend 21. May 2010 12:02

We are proud to announce the release of the latest version of VIBlend Silverlight Controls.

Our main efforts for this release were focused on the Silverlight 4.0 and Visual Studio 2010 support. Another major improvement is the availability of three new themes - Office 2010 Blue, Office 2010 Black and Office 2010 Silver.

See our Silverlight Controls Live Demo and Download a free trial today. 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , ,

How to create a scrollable Menu in Silverlight

by viblend 8. May 2010 18:30

In case the available height is too small to accommodate a group of menu items, the group becomes scrollable.  Each menu item has a DropDownHeight and VerticalScrollBarVisibility properties. The DropDownHeight property is used to restrict the displayed height of a group of menu items, while the VerticalScrollBarVisibility property defines whether the item allows vertical scrolling or not.

The following code example demonstrates how to create a scrollable menu.

[XAML]

         <viblend:Menu Name="Menu" Width="400" Height="20">
                <viblend:MenuItem RootNormalForeBrush="Black" DropDownHeight="150" VerticalScrollBarVisibility="Visible" Text="File">
                    <viblend:MenuItem Text="Mail Message" ImageSource="images/mail.png"/>
                    <viblend:MenuItem Text="Note" ImageSource="images/Note.png"/>
                    <viblend:MenuItem Text="Contact" ImageSource="images/contact.png" />
                    <viblend:MenuItem Text="Appointment" ImageSource="images/Appointment.png"/>
                    <viblend:MenuItem Text="Task" ImageSource="images/Task.png" />
                    <viblend:MenuItem Text="Folder" ImageSource="images/folder.png"/>
                </viblend:MenuItem>
            </viblend:Menu>

VIBlend Menu for Silverlight is a free component that is part of the VIBlend Controls for Silverlight package.

How to add a control in OutlookPane for Silverlight

by viblend 23. March 2010 05:07

In the new release of VIBlend Controls for Silverlight, we added several new controls. One of them is the OutlookPane control. In this blog post we show you how to add any control as a content to it.

At first you need to add references to the NavigationPanes.dll, VIBlendUtilities.dll and Extensions.dll in order to use the OutlookPane and Calendar controls. Then you should create the DataTemplates for the OutlookPane items. The CalendarTemplate simply adds an Image on the left side of a TextBlock. In the source code below, this template is used to define the look of the OutlookPaneItem’s header. The other data template is the ShortCalendarTemplate which is used when the OutlookPaneItem is collapsed or  shown in the OutlookPane’s status area.  After the creation of the DataTemplates,  you should add a new instance of the OutlookPane control and insert a new OutlookPaneItem to it. Finally, put a new Calendar control as a content of the OutlookPaneItem.

Source Code:

<Grid x:Name="LayoutRoot">
        <Grid.Resources>
            <DataTemplate x:Name="CalendarTemplate">
              <StackPanel Orientation="Horizontal">
                    <Image Margin="2" Width="18" HorizontalAlignment="Left" Height="18" Source="calendarIcon.png"></Image>
                    <TextBlock Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left" FontWeight="Bold" Text="Calendar"></TextBlock>
            </StackPanel>
            </DataTemplate>
            <DataTemplate x:Name="ShortCalendarTemplate">
                <Image Margin="2" Width="18" HorizontalAlignment="Left" Height="18" Source="calendarIcon.png"></Image>
            </DataTemplate>     
        </Grid.Resources>
        <viblend:OutlookPane Width="250" Height="300" VerticalAlignment="Center" HorizontalAlignment="Center">
                <viblend:OutlookPaneItem IsSelected="True" MenuItemHeader="Calendar" CollapsedDefaultHeaderTemplate="{StaticResource ShortCalendarTemplate}" 
                                             CollapsedStatusContentTemplate="{StaticResource ShortCalendarTemplate}"
                                             DisplayHeader="Calendar"
                                             DefaultHeaderTemplate="{StaticResource CalendarTemplate}"
                                   >
                <toolkit:Calendar VerticalAlignment="Center" HorizontalAlignment="Center"></toolkit:Calendar>
            </viblend:OutlookPaneItem>
        </viblend:OutlookPane>
  </Grid>

Here is the result:

   

VIBlend Silverlight Controls - Released

by viblend 10. November 2009 13:59
We are proud to announce the official release of VIBlend Controls for Silverlight - professional suite of easy to use and feature complete .NET user interface controls for Microsoft Silverlight. VIBlend Silverlight Controls allow you to develop cross-platform rich internet applications (RIA) for a wide range of business scenarios.
VIBlend Silverlight Controls is the first toolkit to introduce a fully functional OLAP DataGrid control for Silverlight. VIBlend DataGrid for Silverlight brings together the features of traditional data grid controls, hierarchical grids and Excel-like pivot tables, and delivers consistent and powerful end-to-end functionality.

VIBlend Silverlight Controls is available for purchase online at http://www.viblend.com
A full feature trial is available for download at http://www.viblend.com and partner websites.

About the author

Some text that describes me

Recent comments

None

Copyright © 2009 VIBlend  
ALL RIGHTS RESERVED  
 
Terms of Use | Privacy Policy
WinForms Controls Purchase Online About Us
       
DataGrid Navigation Pane Technical Support Blog
ScrollBar TreeView
ListBox ProgressBar Downloads Register
ComboBox Buttons
TabControl Editors Documentation Client Login

VIBlend Blog is powered by BlogEngine.NET