如何将值绑定回数据源

编程入门 行业动态 更新时间:2024-10-28 13:25:53
本文介绍了如何将值绑定回数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何将UserControl字段值绑定到视图模型的属性. 我有一个AutoCompleteComboBox,它绑定到IEnumerable< string>.现在,应该将在AutoCompleteTextBox中输入的Text绑定到ViewModel的属性.但是它正在分配空值. 下面是代码: AutoCompleteComboBox.xaml文件具有以下代码:

How to bind a UserControl Field value to the property of a View Model. I have a AutoCompleteComboBox, which is binded to IEnumerable<string>. Now the Text which is entered in the AutoCompleteTextBox should be binded to the property of a ViewModel. But it is assigning null value. Below is the code: AutoCompleteComboBox.xaml file has below code:

<UserControl x:Class="EET.UI.Controls.UserControls.AutoCompleteComboBox" xmlns="schemas.microsoft/winfx/2006/xaml/presentation" xmlns:x="schemas.microsoft/winfx/2006/xaml" xmlns:contro="clr-namespace=EET.MDM.UI.Modules" Panel.ZIndex="10"> <Canvas> <TextBox x:Name="autoTextBox" Height="25" MinWidth="150" Margin="0,0,10,0" TextWrapping="NoWrap" > </TextBox> <ListBox x:Name="suggestionListBox" SelectionChanged="suggestionListBox_SelectionChanged" Background="LightYellow" Visibility="Collapsed" MinWidth="150" Margin="0,25,0,-25"/>

MyTestPage.xaml文件具有下面的代码,该代码使用上面的AutoCompleteComboBox.xaml用户控件:

MyTestPage.xaml file has below code which uses above AutoCompleteComboBox.xaml usercontrol:

<controls:autocompletecombobox datacontext="{Binding StrParentCounterParties}" x:name="acControl" width="200" grid.row="0" grid.column="1" margin="3" horizontalalignment="Left" xmlns:x="#unknown" xmlns:controls="#unknown"> </controls:autocompletecombobox>

在此,"StrParentCounterParties"是IEnumerable< string>.

Here "StrParentCounterParties" is IEnumerable<string> collection.

推荐答案

<TextBox x:Name="autoTextBox" Height="25" MinWidth="150" Margin="0,0,10,0" TextWrapping="NoWrap" >

没有任何绑定.也许您错过了它.

does not have any binding in it. Perhaps you have missed it out.

更多推荐

如何将值绑定回数据源

本文发布于:2023-11-12 23:23:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582792.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据源   绑定   如何将

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!