这是我的代码:
<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的样子:
现在我想将鼠标悬停在上方以放大文本,我该怎么做?
最佳答案
就是这样吗
<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来同时放大两者。
关于wpf - WPF-所选更改上的ListView项目字体大小,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3917704/