c# – Itemscontrol中的Itemscontrol并使用自定义数据绑定它们
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – Itemscontrol中的Itemscontrol并使用自定义数据绑定它们,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1749字,纯文字阅读大概需要3分钟。
内容图文
我是WPF的新手.我一直在努力做到以下几点:
以下是我的数据结构:
public class TokenItems {public string items {get;set;} public int quantity {get;set}}
public class Token { public int tokenNo {get;set;} public string name {get;set;} public List<TokenItems> currentItems {get;set;}}
public List<Token> tokenList = new List<Token>();
XAML:
<ItemsControl Name="ParentControl">
....
<DataTemplate>
<TextBlock Content="{Binding tokenNo}"/>
<Itemscontrol Name="{Binding tokenNo}"> ?? I tried and want dynamic naming or any other solution for this {Binding name} just won't work i know.??
...
<DataTemplate>
<Button>
<Grid>
...
<TextBlock Content="{Binding items}/>
<TextBlock Content="{Binding quantity}/>
</DataTemplate>
</Itemscontrol>
....
</DataTemplate>
</Itemscontrol>
我将所有必要的数据添加到tokenList并执行以下操作:
ParentControl.ItemsSource = tokenList;
毫无疑问,为ParentControl正确绑定了所有内容.现在我想用列表currentItems填充它的子Itemcontrol.由于我有多个父控件,我需要动态命名到子项Itemscontrol.此外,我无法从代码访问子ItemsControl.
如何做到这一点?我不知道ItemsControl本身是否存在子ItemsControl.
请建议我解决此问题的任何解决方案或替代解决方案.
编辑:我希望用户看到令牌号,时间等,以及要由交互式按钮列表替换的项目列表.
更新:略微修改了XAML内容.子项ItemsControl在DataTemplate中.
解决方法:
你不应该在itemscontrol中命名,如果你想让itemscontrol触发某些东西,请使用itemtemplate中的按钮:
<ItemsControl ItemsSource="{Binding tokenList}">
<ItemsControl ItemsSource="{Binding currentItems}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding TokenNo}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ItemsControl>
你可以添加你需要在datatemplate标签中显示的任何内容.在我的示例中,按钮上的文本将是它在父节点中找到的TokenNo,即通过tokenlist绑定显示的Token.
内容总结
以上是互联网集市为您收集整理的c# – Itemscontrol中的Itemscontrol并使用自定义数据绑定它们全部内容,希望文章能够帮你解决c# – Itemscontrol中的Itemscontrol并使用自定义数据绑定它们所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。