gpt4 book ai didi

silverlight - WP7 : Change the visibility of an item in a selected listbox item

转载 作者:行者123 更新时间:2023-12-04 02:35:40 26 4
gpt4 key购买 nike

我有一个定义了以下数据模板的列表框:

<DataTemplate x:Name="MyTemplate">
<StackPanel>
<TextBlock Name="textblock1" Text="{Binding Name}" />
<TextBlock Name="textblock2" Text="{Binding SurName}" />
<StackPanel Name="extrainfo" Visibility="Collapsed">
<TextBlock Name="textblock3" Text="{Binding Address}" />
<TextBlock Name="textblock4" Text="{Binding Phone}" />
<TextBlock Name="textblock5" Text="{Binding Email}" />
</StackPanel>
</StackPanel>
</DataTemplate>

列表框:
<ListBox Name="myListBox" ItemTemplate="{StaticResource MyTemplate}" ItemsSource="{Binding UserList}" />

问题如下;当用户在列表框中选择一个项目时,我想通过将堆栈面板的可见性设置为可见来显示附加信息。

任何想法如何实现这一点(通过xaml或c#)?我试图改变 Storyboard,但我用这种方法并没有走得很远。

最佳答案

创建 ItemContainerStyle具有默认值 ContentControl介绍ItemTemplate的内容但也有用 Visibility 定义的细节内容设置为 Collapsed .然后,更新“选定”VisualState以便它设置 Visibility详细信息面板到 Visible :

<VisualState x:Name="Selected">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground"
Storyboard.TargetName="ContentContainer">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneAccentBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility"
Storyboard.TargetName="Details">
<DiscreteObjectKeyFrame KeyTime="0" Value="Visibile"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
...
<StackPanel>
<ContentControl
x:Name="ContentContainer"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
<Grid x:Name="Details">
<!-- Put the content of your details panel here. -->
</Grid>
</StackPanel>

关于silverlight - WP7 : Change the visibility of an item in a selected listbox item,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4957336/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com