Silverlight 中通用列表的数据绑定折叠式
给定一个包含两个属性(IdentityType 和 Name)的对象列表,格式如下:
IdentityType | Name
A | One
A | Two
A | Three
B | Four
B | Five
C | Six
有没有一种方法可以声明式数据绑定,以便手风琴显示如下?
A
- One
- Two
- Three
B
- Four
- Five
C
- Six
到目前为止,我能得到的最好的结果是每个项目都有一个面板标题,如下所示:
<toolkit:Accordion ItemsSource="{Binding Path=Identities}" Grid.Row="2" SelectionMode="ZeroOrMore">
<toolkit:Accordion.ItemTemplate>
<DataTemplate >
<TextBlock Text="{Binding IdentityType, Converter={StaticResource EnumDescriptionConverter}}"/>
</DataTemplate>
</toolkit:Accordion.ItemTemplate>
<toolkit:Accordion.ContentTemplate>
<DataTemplate>
<StackPanel Margin="5" Orientation="Horizontal">
<TextBlock Text="{Binding Name}" Foreground="White" />
</StackPanel>
</DataTemplate>
</toolkit:Accordion.ContentTemplate>
</toolkit:Accordion>
我是 Silverlight 的新手,所以我可能会错过一些非常明显的东西,但我们将非常感谢任何帮助!
Given a list of objects containing two properties (IdentityType and Name) in the format:
IdentityType | Name
A | One
A | Two
A | Three
B | Four
B | Five
C | Six
Is there a way to declaratively databind that so the accordion displays like this?
A
- One
- Two
- Three
B
- Four
- Five
C
- Six
So far the best I can get is a panel header for each item, like so:
<toolkit:Accordion ItemsSource="{Binding Path=Identities}" Grid.Row="2" SelectionMode="ZeroOrMore">
<toolkit:Accordion.ItemTemplate>
<DataTemplate >
<TextBlock Text="{Binding IdentityType, Converter={StaticResource EnumDescriptionConverter}}"/>
</DataTemplate>
</toolkit:Accordion.ItemTemplate>
<toolkit:Accordion.ContentTemplate>
<DataTemplate>
<StackPanel Margin="5" Orientation="Horizontal">
<TextBlock Text="{Binding Name}" Foreground="White" />
</StackPanel>
</DataTemplate>
</toolkit:Accordion.ContentTemplate>
</toolkit:Accordion>
I'm new to Silverlight so I could be missing something blindingly obvious, but any help would be very much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用模型(初始列表)和视图(标记)之间的视图模型来执行此操作。
假设您的模型如下...
您的视图模型结构应该是...
然后您的视图可以创建 DataContextClass 的实例,将其分配给它自己的 DataContext 属性,然后使用此标记...
You can do this with a view model inbetween your model (the initail list) and your view (the markup).
Assuming your model is as follows...
Your View Model structure should be...
Then your view can create an instance of your DataContextClass, assign it to it's own DataContext property and then use this markup...
您也可以使用元组代替。
代码变为:
}
Xaml 变为:
我希望它有帮助
You can also use Tuple instead.
Code becomes :
}
Xaml become :
I hope it helps