【问题标题】:WPF - ListView Item on Selected change Font sizeWPF - 选定更改字体大小的 ListView 项目
【发布时间】:2010-10-12 18:13:58
【问题描述】:

这是我的代码:

<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 的样子:

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

【问题讨论】:

    标签: wpf triggers styles controltemplate


    【解决方案1】:

    就这样做?

    <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 以放大两者。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多