GridLengthConverter Class
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace: http://schemas.microsoft.com/winfx/2006/xaml/presentation
The following example shows how to create and use an instance of GridLengthConverter. The example defines a custom method called changeCol, which passes the ListBoxItem to a GridLengthConverter that converts the Content of a ListBoxItem to an instance of GridLength. The converted value is then passed back as the value of the Width property of the ColumnDefinition element.
The example also defines a second custom method, called changeColVal. This custom method converts the Value of a Slider to a String and then passes that value back to the ColumnDefinition as the Width of the element.
Note that a separate Extensible Application Markup Language (XAML) file defines the contents of a ListBoxItem.
To view the complete sample, including the related XAML file, see Instantiating and Using a GridLengthConverter Object Sample.
Public Sub changeColVal(ByVal sender As Object, ByVal args As RoutedPropertyChangedEventArgs(Of Double)) txt1.Text = "Current Grid Column is " + hs1.Value.ToString() End Sub Public Sub changeCol(ByVal sender As Object, ByVal args As SelectionChangedEventArgs) Dim li1 As ListBoxItem = CType(CType(sender, ListBox).SelectedItem, ListBoxItem) Dim myGridLengthConverter As System.Windows.GridLengthConverter = New System.Windows.GridLengthConverter() If (hs1.Value = 0) Then Dim gl1 As GridLength = CType(myGridLengthConverter.ConvertFromString(li1.Content.ToString()), GridLength) col1.Width = gl1 ElseIf (hs1.Value = 1) Then Dim gl2 As GridLength = CType(myGridLengthConverter.ConvertFromString(li1.Content.ToString()), GridLength) col2.Width = gl2 ElseIf (hs1.Value = 2) Then Dim gl3 As GridLength = CType(myGridLengthConverter.ConvertFromString(li1.Content.ToString()), GridLength) col3.Width = gl3 End If End Sub
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.