Use LengthConverter : IValueConverter « Windows Presentation Foundation « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Windows Presentation Foundation » IValueConverter 
16.100.2.Use LengthConverter
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="Canvas_Positioning_Properties.Window1"
    Title="Canvas Positioning Properties">
  <StackPanel>
    <Canvas Name="canvas1" Height="300">
        <TextBlock Name="text1" FontWeight="Bold" Canvas.Left="0" Canvas.Right="0" Canvas.Top="0" Canvas.Bottom="0">A TextBlock.</TextBlock>
  </Canvas>
    <ListBox Grid.Column="3" Grid.Row="1" VerticalAlignment="Top" Width="60" Margin="10,0,0,0" SelectionChanged="ChangeLeft">

      <ListBoxItem>Auto</ListBoxItem>      
      <ListBoxItem>10</ListBoxItem>
      <ListBoxItem>20</ListBoxItem>
      <ListBoxItem>30</ListBoxItem>
      <ListBoxItem>40</ListBoxItem>
      <ListBoxItem>50</ListBoxItem>
      <ListBoxItem>60</ListBoxItem>
      <ListBoxItem>70</ListBoxItem>
      <ListBoxItem>80</ListBoxItem>
      <ListBoxItem>90</ListBoxItem>
      <ListBoxItem>100</ListBoxItem>      
    </ListBox>
  </StackPanel>        
</Window>
//File:Window.xaml.vb

Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Navigation
Imports System.Windows.Shapes
Imports System.Windows.Data

Namespace Canvas_Positioning_Properties

  Public Partial Class Window1
    Inherits Window
    Public Sub ChangeLeft(sender As Object, args As SelectionChangedEventArgs)
      Dim li As ListBoxItem = TryCast(TryCast(sender, ListBox).SelectedItem, ListBoxItem)
      Dim myLengthConverter As New LengthConverter()
      Dim db1 As [Double= CType(myLengthConverter.ConvertFromString(li.Content.ToString())[Double])
      Canvas.SetLeft(text1, db1)
      Console.WriteLine(myLengthConverter.ConvertToString(Canvas.GetLeft(text1)))
    End Sub


  End Class
End Namespace
WPF Use Length Converter
16.100.IValueConverter
16.100.1.Decimal ScrollBar Window with extending IValueConverterDecimal ScrollBar Window with extending IValueConverter
16.100.2.Use LengthConverterUse LengthConverter
16.100.3.Debug Data Bindings Using an Empty IValueConverterDebug Data Bindings Using an Empty IValueConverter
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.