2008年12月6日 星期六

wpf程式設計--圖形List2

加上MouseOver透明度更改功能。

image

<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="550" Width="419">
     <Window.Resources>
        <Style TargetType="Image">
            <Setter Property="Width" Value="120" />
            <Setter Property="Margin" Value="5" />
            <Setter Property="Opacity" Value="0.2" />
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Trigger.Setters>
                        <Setter Property="Opacity" Value="1" />
                    </Trigger.Setters>
                </Trigger>
            </Style.Triggers>
        </Style>
        <Style TargetType="ListBox">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBox">
                        <Border BorderThickness="1" BorderBrush="Black">
                            <ScrollViewer>
                                <StackPanel IsItemsHost="True" Orientation="Vertical"/>
                            </ScrollViewer>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <StackPanel Margin="93,32,98,0" Height="441" VerticalAlignment="Top">
            <Label FontSize="30" HorizontalAlignment="Center">Image List</Label>
            <ListBox Width="155" HorizontalAlignment="Center" Height="385">
                <Image Source="Humpback Whale.jpg" />
                <Label FontSize="12" HorizontalAlignment="Center">Humpback Whale</Label>
                <Image Source="Oryx Antelope.jpg"  />
                <Label FontSize="12" HorizontalAlignment="Center">Oryx Antelope</Label>
                <Image Source="Toco Toucan.jpg"  />
                <Label FontSize="12" HorizontalAlignment="Center">Toco Toucan</Label>
                <Image Source="Green Sea Turtle.jpg"  />
                <Label FontSize="12" HorizontalAlignment="Center">Green Sea Turtle</Label>
            </ListBox>
        </StackPanel>
    </Grid>
</Window>

沒有留言: