如何将值绑定回数据源 [英] How to Bind value back to the Datasource

查看:58
本文介绍了如何将值绑定回数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将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="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/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.


这篇关于如何将值绑定回数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆