Convert contents of a ListBoxItem to an instance of Thickness by using the BrushConverter : Brush « Windows Presentation Foundation « VB.Net






Convert contents of a ListBoxItem to an instance of Thickness by using the BrushConverter

Convert contents of a ListBoxItem to an instance of Thickness by using the BrushConverter
      

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="ThicknessConverter_Csharp.Window1"
    Title="ThicknessConverter Sample">
  <DockPanel Width="400" HorizontalAlignment="Left" VerticalAlignment="Top">
    <TextBlock DockPanel.Dock="Top" FontFamily="Verdana" FontSize="18" FontWeight="Bold" Margin="5">
      ThicknessConverter Sample</TextBlock>
    <Border Name="border1" Height="300" Width="300" Border.BorderThickness="2" Border.BorderBrush="Black" DockPanel.Dock="Top">
      <Grid Height="30" VerticalAlignment="Top">
        <Grid.RowDefinitions>
          <RowDefinition/>
          <RowDefinition/>
        </Grid.RowDefinitions>
        <TextBlock Grid.Row="0" Name="bThickness"/>
        <TextBlock Grid.Row="1" Name="bColor"/>
      </Grid>
    </Border>
    <Grid DockPanel.Dock="Top">
      <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
      </Grid.ColumnDefinitions>
      <TextBlock Grid.Row="1" Grid.Column="2" TextWrapping="Wrap">Set the BorderBrush Property:</TextBlock>
      <ListBox VerticalAlignment="Top" Grid.Column="3" Grid.Row="1" Width="60" Height="50" Margin="5" SelectionChanged="changeColor">
        <ListBoxItem>Red</ListBoxItem>
        <ListBoxItem>Green</ListBoxItem>
        <ListBoxItem>Blue</ListBoxItem>
        <ListBoxItem>Yellow</ListBoxItem>
        <ListBoxItem>Orange</ListBoxItem>
        <ListBoxItem>Purple</ListBoxItem>
        <ListBoxItem>Silver</ListBoxItem>
        <ListBoxItem>Pink</ListBoxItem>
        <ListBoxItem>Maroon</ListBoxItem>
        <ListBoxItem>Brown</ListBoxItem>
        <ListBoxItem>Black</ListBoxItem>
      </ListBox>
    </Grid>
  </DockPanel>        
</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.Media

Namespace ThicknessConverter_Csharp
  Public Partial Class Window1
    Inherits Window

    Public Sub changeColor(sender As Object, args As SelectionChangedEventArgs)
      Dim li2 As ListBoxItem = TryCast(TryCast(sender, ListBox).SelectedItem, ListBoxItem)
      Dim myBrushConverter As New BrushConverter()
      border1.BorderBrush = DirectCast(myBrushConverter.ConvertFromString(DirectCast(li2.Content, String)), Brush)
      bColor.Text = "Border.Borderbrush =" & li2.Content.ToString()
    End Sub
  End Class
End Namespace

   
    
    
    
    
    
  








Related examples in the same category

1.Fill = Brushes.RedFill = Brushes.Red
2.Fill = new SolidColorBrush(Colors.Green)Fill = new SolidColorBrush(Colors.Green)
3.Fill = new SolidColorBrush(Color.FromRgb(0, 0, 255))Fill = new SolidColorBrush(Color.FromRgb(0, 0, 255))
4.Fill = new SolidColorBrush(Color.FromArgb(100, 0, 0, 255));Fill = new SolidColorBrush(Color.FromArgb(100, 0, 0, 255));
5.Using the SolidColorBrush typeUsing the SolidColorBrush type
6.Using the SolidColorBrush and Color typeUsing the SolidColorBrush and Color type
7.Describes the brush's color using ARGB values. Each value has a range of 0-255.Describes the brush's color using ARGB values. Each value has a range of 0-255.
8.Shows the predefined brushes defined by the System.Brushes class.Shows the predefined brushes defined by the System.Brushes class.
9.Drawing Brush In XAMLDrawing Brush In XAML
10.Use SolidColorBrush to paint RectangleUse SolidColorBrush to paint Rectangle
11.Solid brush using type converterSolid brush using type converter
12.Fill the underline decoration with a solid color brush in VBFill the underline decoration with a solid color brush in VB
13.Fill the strikethrough decoration with a solid color brush in VBFill the strikethrough decoration with a solid color brush in VB
14.Colors and BrushesColors and Brushes
15.Predefined brush in Brushes ClassPredefined brush in Brushes Class
16.Solid Color Brush In Code with predefined brushSolid Color Brush In Code with predefined brush
17.Solid Color Brush In Code with SolidColorBrushSolid Color Brush In Code with SolidColorBrush
18.Solid Color Brush In Code with SolidColorBrush and RGB colorSolid Color Brush In Code with SolidColorBrush and RGB color
19.Fill up the ListBox with brush namesFill up the ListBox with brush names
20.DrawingBrush with DrawingGroupDrawingBrush with DrawingGroup