WPF VB.Net Tutorial

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="Grid_Convert_Value_Csharp.Window1"
    Title="Dynamically Change Margin Property Sample">
  
    Grid Margin Property Sample
        
            
              
                
              

              
                
              

                Some Text.
          
        
        
        
          
        

        
          
          
        

              
                  10
                  20
                  30
                  40
                  50
                  60
                  70
                  80
                  90
                  100
              
          
              

//File:Window.xaml.vb
Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Navigation
Namespace Grid_Convert_Value_Csharp
  Public Partial Class Window1
    Inherits Window
    Public Sub ChangeMargin(sender As Object, args As SelectionChangedEventArgs)
      Dim li As ListBoxItem = TryCast(TryCast(sender, ListBox).SelectedItem, ListBoxItem)
      Dim myThicknessConverter As New ThicknessConverter()
      Dim th1 As Thickness = CType(myThicknessConverter.ConvertFromString(li.Content.ToString()), Thickness)
      text1.Margin = th1
      Dim st1 As [String] = DirectCast(myThicknessConverter.ConvertToString(text1.Margin), [String])
      Console.WriteLine("Margin: " & st1)
    End Sub
  End Class
End Namespace