Click here to Skip to main content
16,018,460 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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:

XML
<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 file has below code which uses above AutoCompleteComboBox.xaml usercontrol:

XML
<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>


Here "StrParentCounterParties" is IEnumerable<string> collection.
Posted

1 solution

VB
<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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900