WPF - 所选更改字体大小的ListView项目

时间:2010-10-12 18:13:58

标签: wpf triggers styles controltemplate

这是我的代码:

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <ListBox ItemsSource="{Binding Persons}">
        <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Border Background="White" BorderThickness="5" Name="Bd">
                                <Border.Style>
                                    <Style TargetType="Border">
                                        <Setter Property="BorderBrush" Value="White" />
                                    </Style>
                                </Border.Style>
                                <StackPanel Orientation="Horizontal" >
                                    <TextBlock Margin="10" Name="t1" Text="{Binding Name}"/>
                                    <TextBlock Margin="10" Text="{Binding Age}"/>
                                </StackPanel>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="Bd" Property="BorderBrush" Value="HotPink" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ListBox.ItemContainerStyle>

    </ListBox>
</Grid>

这就是MouseOver的样子: alt text

现在我想要将鼠标放大以放大文字,我该怎么做?

1 个答案:

答案 0 :(得分:0)

这样做吗?

<ControlTemplate.Triggers>
    <Trigger Property="IsMouseOver" Value="True">
        <Setter TargetName="Bd" Property="BorderBrush" Value="HotPink" />
        <Setter TargetName="t1" Property="FontSize" Value="72" />
    </Trigger>
</ControlTemplate.Triggers>

这会放大第一个文本块 - 你需要命名第二个文本块,并在TargetName属性中使用新名称制作另一个setter来扩大它们。