Autocompletebox SelectedText Bug
S

1

6

I want to bind both the SelectedText and SelectedItem properties of an AutocompleteBox because my client wants to be able to input text and select from the list also. It's working properly but ...

The MainPage has one DataGrid. When I select a record from the Grid (i.e. SelectedItem), I want to set it in a popup window's AutocompleteBox. Some times it works but some times it doesn't.

What should I do for this issue?

This is my XAML:

<Sdk:AutoCompleteBox Grid.Column="3" Grid.Row="3" Height="18" Width="150" 
     IsTextCompletionEnabled="True" TabIndex="9" HorizontalAlignment="Left"

     Text="{Binding ElementName=ResEdit,Path=DataContext.SelectedDemoText,Mode=TwoWay}"
     ItemsSource="{Binding ElementName=ResEdit,Path=DataContext.DemoList,Mode=OneWay}"
     ItemTemplate="{StaticResource DemoTemplate}"
     ValueMemberPath="DemoCode" 
     LostFocus="AutoCompleteBox_LostFocus"
     Margin="0,0,21,0" Padding="0">
  </Sdk:AutoCompleteBox>

This property is in my view-model and bound to the DataGrid:

public InvoicesDTO SelectedInvoice
{
    get { return _selectedInvoice; }
    set
    {
        SelectedInvoice = value;
        SelectedDomoText = SelectedInvoice.DemoText.Trim();
        RaisePropertyChanged("SelectedInvoice");
    }
}
Speechless answered 28/12, 2012 at 5:47 Comment(3)
I Have Issue With set SelectedText Property Some time it should set proper and some time not set properSpeechless
can you post some of your code sample and/or image of the same?Jaquesdalcroze
I Think You Should Help me with this codeSpeechless
C
3

You should not use both function SelectedText and SelectedItem in autocomplete. it's a bug of AutoCompleteBox..... A better way is to set the visiblity of the textbox and AutoCompleteBox on GotFocus and LossFocus. This Way You Will Defiantly Solve You Problem

 private void DemoAutoComplete_LostFocus(object sender, RoutedEventArgs e)
            {
                DemoTextBox.Visibility = Visibility.Visible;
                DemoAutoComplete.Visibility = Visibility.Collapsed;
                DemoTextBox.Text = OCRAutoComplete.Text;

                ((DemoVM)this.DataContext).SelectedDemoText = DemoAutoComplete.Text;
            }



private void DemoTextBox_GotFocus(object sender, RoutedEventArgs e)
    {
        DemoAutoComplete.Text = OctTextBox.Text;
        DemoTextBox.Visibility = Visibility.Collapsed;
        DemoAutoComplete.Visibility = Visibility.Visible;
        DemoAutoComplete.Focus();
    }
Catarrhine answered 4/2, 2013 at 6:3 Comment(1)
your ans is no compitible with my questionSpeechless

© 2022 - 2024 — McMap. All rights reserved.