WPF - ListView Item on Selected change Font size

情到浓时终转凉″ 提交于 2020-01-24 11:23:47

问题


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:

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


回答1:


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.



来源:https://stackoverflow.com/questions/3917704/wpf-listview-item-on-selected-change-font-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!