Silverlight/XAML – Learning by Coding

[ sl2_flexible_layout.xaml --> Grafik anzeigen ]

  1: <?xml version="1.0" encoding="UTF-8"?>
  2: <!-- coded by Thomas Meinike 09/08 -->
  3: <UserControl x:Class="sl2_flexible_layout.Page"
  4:   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  5:   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  6:   Width="Auto" Height="Auto">
  7: 
  8:   <UserControl.Resources>
  9: 
 10:     <Style x:Key="btnstyle" TargetType="Button">
 11:       <Setter Property="Height" Value="40"/>
 12:       <Setter Property="Width" Value="170"/>
 13:       <Setter Property="Cursor" Value="Hand"/>
 14:       <Setter Property="Foreground" Value="#00C"/>
 15:       <Setter Property="FontSize" Value="16"/>
 16:       <Setter Property="FontFamily" Value="Arial"/>
 17:       <Setter Property="HorizontalAlignment" Value="Stretch"/>
 18:       <Setter Property="VerticalAlignment" Value="Top"/>     
 19:       <Setter Property="Background">
 20:         <Setter.Value>
 21:           <LinearGradientBrush>
 22:             <GradientStop Offset="0" Color="#6CF"/>
 23:             <GradientStop Offset="1" Color="#FC0"/>
 24:           </LinearGradientBrush>
 25:         </Setter.Value>
 26:       </Setter>
 27:     </Style>
 28: 
 29:     <Style x:Key="txtstyle" TargetType="TextBlock">
 30:       <Setter Property="Foreground" Value="#000"/>
 31:       <Setter Property="FontSize" Value="24"/>
 32:       <Setter Property="FontFamily" Value="Arial"/>
 33:       <Setter Property="HorizontalAlignment" Value="Center"/>
 34:       <Setter Property="VerticalAlignment" Value="Center"/>
 35:     </Style>
 36: 
 37:   </UserControl.Resources>
 38: 
 39: 
 40:   <Grid x:Name="container" Background="#FFF">
 41: 
 42:     <Grid.ColumnDefinitions>
 43:       <ColumnDefinition Width="170"/>
 44:       <ColumnDefinition Width="*"/>
 45:     </Grid.ColumnDefinitions>
 46: 
 47:     <Grid.RowDefinitions>
 48:       <RowDefinition Height="100"/>
 49:       <RowDefinition Height="*"/>
 50:       <RowDefinition Height="50"/>
 51:     </Grid.RowDefinitions>
 52: 
 53:     <Grid x:Name="header" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Height="100"
 54:       Background="#6CF" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
 55:       <TextBlock Text="Header-Bereich" Style="{StaticResource txtstyle}"/>
 56:     </Grid>
 57: 
 58:     <StackPanel x:Name="navi" Grid.Row="1" Grid.Column="0" Width="170"
 59:       HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
 60:       <TextBlock Text="Navigation" Style="{StaticResource txtstyle}" Margin="0,0,0,10"/>
 61:       <Button x:Name="navi_btn1" Style="{StaticResource btnstyle}" Content="Button 1" Click="BtnClick"/>
 62:       <Button x:Name="navi_btn2" Style="{StaticResource btnstyle}" Content="Button 2" Click="BtnClick"/>
 63:       <Button x:Name="navi_btn3" Style="{StaticResource btnstyle}" Content="Button 3" Click="BtnClick"/>
 64:       <Button x:Name="navi_btn4" Style="{StaticResource btnstyle}" Content="Button 4" Click="BtnClick"/>
 65:       <Button x:Name="navi_btn5" Style="{StaticResource btnstyle}" Content="Button 5" Click="BtnClick"/>
 66:     </StackPanel>
 67: 
 68:     <ScrollViewer x:Name="content" Grid.Row="1" Grid.Column="1" Grid.RowSpan="1" Width="Auto"
 69:       BorderBrush="#FFF" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
 70:       HorizontalScrollBarVisibility="Auto"  VerticalScrollBarVisibility="Auto">
 71:       <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
 72:         <TextBlock Text="Content-Bereich" Style="{StaticResource txtstyle}"/>
 73:         <TextBlock x:Name="output" Text="..." Style="{StaticResource txtstyle}"
 74:           FontSize="14" Foreground="#F00"/>
 75:       </StackPanel>
 76:     </ScrollViewer>
 77: 
 78:     <Grid x:Name="footer" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Height="50"
 79:       Background="#FC0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
 80:       <TextBlock Text="Footer-Bereich" Style="{StaticResource txtstyle}"/>
 81:     </Grid>
 82: 
 83:     <Path Data="M172,100 L172,470" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left"
 84:       VerticalAlignment="Stretch" Width="1" Stretch="Fill" Stroke="#CCC" StrokeThickness="1"/>
 85: 
 86:   </Grid>
 87: 
 88: 
 89:   <!-- // zusätzlich verwendeter VB.NET-Code in Page.xaml.vb:
 90: 
 91:   Partial Public Class Page
 92:     Inherits UserControl
 93: 
 94:     Public Sub New()
 95:       InitializeComponent()
 96:     End Sub
 97: 
 98:     Private Sub BtnClick(ByVal sender As System.ObjectByVal e As System.Windows.RoutedEventArgs)
 99:       Dim btn_name As String sender.Name.ToString
100:       output.Text "Button " btn_name.Substring(btn_name.Length 1) + " wurde gedrückt."
101:     End Sub
102: 
103:   End Class
104: 
105:   -->
106: 
107: </UserControl>

[zum Anfang]