Change Height : ListBox Style « Windows Presentation Foundation « VB.Net Tutorial






<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="Height_MinHeight_MaxHeight.Window1"
    Title="Height Properties Sample">
  <StackPanel Margin="10">
      <Canvas Height="200" MinWidth="200" Name="myCanvas">
           <Rectangle HorizontalAlignment="Center" Canvas.Top="50" Canvas.Left="50"  Name="rect1" Fill="#4682b4" Height="100" Width="100"/>
      </Canvas>
      <Button Name="Button1" Click="clipRect">Canvas.ClipToBounds="True"</Button>
      <Button Name="Button2" Margin="0,5,5,5" Click="unclipRect">Canvas.ClipToBounds="False"</Button>
    <TextBlock Grid.Row="1" Grid.Column="0" Margin="10,0,0,0" TextWrapping="Wrap">Set the Rectangle Height:</TextBlock>
    <ListBox Grid.Column="1" Grid.Row="1" Margin="10,0,0,0" Height="50" Width="50" SelectionChanged="changeHeight">
      <ListBoxItem>25</ListBoxItem>
      <ListBoxItem>50</ListBoxItem>
      <ListBoxItem>75</ListBoxItem>
      <ListBoxItem>100</ListBoxItem>
      <ListBoxItem>125</ListBoxItem>
      <ListBoxItem>150</ListBoxItem>
      <ListBoxItem>175</ListBoxItem>
      <ListBoxItem>200</ListBoxItem>
    </ListBox>

  </StackPanel>
</Window>

//File:Window.xaml.vb

Imports System
Imports System.Windows
Imports System.Windows.Media
Imports System.Windows.Controls
Imports System.Windows.Documents

Namespace Height_MinHeight_MaxHeight
  Public Partial Class Window1
    Inherits Window
    Public Sub changeHeight(sender As Object, args As SelectionChangedEventArgs)
      Dim li As ListBoxItem = TryCast(TryCast(sender, ListBox).SelectedItem, ListBoxItem)
      Dim sz1 As [Double] = [Double].Parse(li.Content.ToString())
      rect1.Height = sz1
      rect1.UpdateLayout()
      Console.WriteLine("ActualHeight is set to " + rect1.ActualHeight)
      Console.WriteLine("Height is set to " + rect1.Height)
      Console.WriteLine("MinHeight is set to " + rect1.MinHeight)
      Console.WriteLine("MaxHeight is set to " + rect1.MaxHeight)
    End Sub


    Public Sub clipRect(sender As Object, args As RoutedEventArgs)
      myCanvas.ClipToBounds = True
      Console.WriteLine("Canvas.ClipToBounds is set to " + myCanvas.ClipToBounds)
    End Sub
    Public Sub unclipRect(sender As Object, args As RoutedEventArgs)
      myCanvas.ClipToBounds = False
      Console.WriteLine("Canvas.ClipToBounds is set to " + myCanvas.ClipToBounds)
    End Sub
  End Class
End Namespace
WPF Change Height








16.29.ListBox Style
16.29.1.External ListBox styleExternal ListBox style
16.29.2.Define ListBox templateDefine ListBox template
16.29.3.Create a ListBoxItem, set font, content, add the ListBoxItem to the ListBoxCreate a ListBoxItem, set font, content, add the ListBoxItem to the ListBox
16.29.4.Change HeightChange Height
16.29.5.Change MinHeightChange MinHeight
16.29.6.Create a style that will produce a horizontal ListBox.Create a style that will produce a horizontal ListBox.