silverlight-4.0 - 自动完成框选定文本错误

标签 silverlight-4.0 silverlight-3.0 silverlight-5.0 silverlight-toolkit silverlight-2.0

我想绑定(bind) AutocompleteBox 的 SelectedTextSelectedItem 属性,因为我的客户希望能够输入文本并从列表中进行选择。它工作正常,但是...

MainPage 有一个 DataGrid。当我从网格中选择一条记录(即 SelectedItem)时,我想将其设置在弹出窗口的 AutocompleteBox 中。有时它有效,但有时则无效。

这个问题我该怎么办?

这是我的 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>

此属性位于我的 View 模型中并绑定(bind)到 DataGrid:

public InvoicesDTO SelectedInvoice
{
    get { return _selectedInvoice; }
    set
    {
        SelectedInvoice = value;
        SelectedDomoText = SelectedInvoice.DemoText.Trim();
        RaisePropertyChanged("SelectedInvoice");
    }
}

最佳答案

您不应在自动完成中同时使用函数SelectedTextSelectedItem。这是AutoCompleteBox的一个bug......更好的方法是在GotFocus和LossFocus上设置文本框AutoCompleteBox的可见性。这样你就会坚定地解决你的问题

 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();
    }

关于silverlight-4.0 - 自动完成框选定文本错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14065161/

相关文章:

c# - 将权限/身份验证复制到子线程...?

c# - Visual Studio 2010 Silverlight 项目在浏览器中作为文件 ://instead of localhost://打开

c# - 将 Light Switch 与我自己的域对象一起使用

silverlight-4.0 - 如何以编程方式为TabControl创建HeaderTemplate?

silverlight - 寻求 Silverlight 应用程序的字体策略

c# - 使用代码从 ViewModel 绑定(bind)控件中检索 System.ComponentModel.DataAnnotations.DisplayAttribute 属性

silverlight - 如何使用 MediaStreamSource 播放来自 matroska 文件的 h264 帧?

silverlight - Firefox 上的无窗口 Silverlight(和 Flash?)应用程序 : wrong mouse positions reported

c# - "Thickness"的 TypeConverter 不支持从字符串转换

mvvm - 在 Prism EventAggregator 中发布没有 PayLoad 的事件?