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

发布于 2024-09-27 07:38:28 字数 2055 浏览 1 评论 0原文

这是我的代码:

<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

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

this is my code:

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

And this is how MouseOver looks like:
alt text

Now I want the Mouse over To enlarge the text, how can I do that ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

表情可笑 2024-10-04 07:38:28

就这样做吗?

<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 属性中使用新名称创建另一个设置器以放大两个文本块。

Just do this?

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

This will enlarge the first textblock - you need to name the second one and make another setter with the new name in the TargetName property to enlarge both.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文