使用MVVMlight 绑定自定义控件(userControl)
2021/5/20 18:58:16
本文主要是介绍使用MVVMlight 绑定自定义控件(userControl),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
MVVMLight 之绑定自定义控件(userControl)
1.在做WPF程序的时候,避免不了会用到自定义控件;在一个VIEW中使用userControl,在userControl中很可能还包含有userControl;
2.viewModel 中定义好数据;
3.自定义控件如下方式绑定
<ContentControl>
<HardwareControl:DeviceManageListView DataContext="{Binding DataContext,RelativeSource={RelativeSource AncestorType=Window}}"/>
</ContentControl>
这个时候自定义控件中的DataContext与当前viewModel是一致的;根据需要绑定即可;
4.在USerControl 中包含UserControl,绑定方式如下:
<ContentControl Grid.Column="2" >
<my:DeviceManageView DataContext="{Binding DataContext,RelativeSource={RelativeSource AncestorType=UserControl}}" />
</ContentControl>
这个时候自定义控件中的DataContext与当前UserControl是一致的;根据需要绑定即可;
这篇关于使用MVVMlight 绑定自定义控件(userControl)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-26终极指南:Scrum中如何设置需求优先级
- 2024-06-26AI大模型企业应用实战(25)-为Langchain Agent添加记忆功能
- 2024-06-26小白家庭 nas 搭建方案-icode9专业技术文章分享
- 2024-06-23AI大模型企业应用实战(14)-langchain的Embedding
- 2024-06-23AI大模型企业应用实战(15)-langchain核心组件
- 2024-06-23AI大模型企业应用实战(16)-langchain核心组件
- 2024-06-23AI 大模型企业应用实战(06)-初识LangChain
- 2024-06-19EntBot.ai: AI Website Chatbot for Product Guides and Development Doc
- 2024-06-17zero-shot-learning-definition-examples-comparison
- 2024-06-06Package Easy(基于 NSIS 的打包exe安装包工具)使用方法-icode9专业技术文章分享