WPF。当它的选择改变的ListViewItem的大小 [英] WPF. Change size of ListViewItem when it's selected
本文介绍了WPF。当它的选择改变的ListViewItem的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个ListView:
I have a listview:
<ListView Name="SelectedFeeds">
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}"
BasedOn="{StaticResource {x:Type ListViewItem}}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" Name="panel">
<TextBlock x:Name="Title" FontSize="24"
Text="{Binding Title, IsAsync=True}" TextWrapping="Wrap" />
<Label x:Name="PubDate" FontSize="10"
Content="{Binding Path=PubDate, IsAsync=True}" />
<TextBlock my:HtmlParser.HTMLText=
"{Binding Path=Description, IsAsync=True}"
TextWrapping="Wrap"
Width="{Binding ElementName=panel,
Path=ActualWidth}" Height="0" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
有在DataTemplate中TextBlock的大高度。
There is a TextBlock in DataTemplate with large height.
在开始我设置这个文本块的高度,以0,被选中的时候ListViewItem的,我需要设置高度为自动。
At start I'm setting height of this textblock to "0" and when ListViewItem is selected, I need to set that height to "Auto".
这是大概可以使用触发器做的,但我不明白。
This is probably can be done with triggers, but I can't figure it out.
推荐答案
有关触发的方式,在DataTemplate中使用它。
For a trigger approach, use it in the DataTemplate.
<ListView Name="SelectedFeeds">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" Name="panel">
<TextBlock x:Name="Title" FontSize="24"
Text="{Binding Title, IsAsync=True}" TextWrapping="Wrap" />
<Label x:Name="PubDate" FontSize="10"
Content="{Binding Path=PubDate, IsAsync=True}" />
<TextBlock x:Name="TextHolder"
my:HtmlParser.HTMLText=
"{Binding Path=Description, IsAsync=True}"
TextWrapping="Wrap"
Width="{Binding ElementName=panel,
Path=ActualWidth}" Height="0" />
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}" Value="True">
<Setter TargetName="TextHolder" Property="Height" Value="123"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
请注意在 X:。名称
的属性的TextBlock
这篇关于WPF。当它的选择改变的ListViewItem的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文