WPF - 当选中ListView项目时更改字体大小

3

这是我的代码:

<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>

这是鼠标悬停的效果: alt text

现在我想通过鼠标悬停来放大文本,我该怎么做?

1个回答

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以放大两个文本块。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接