MainPage有一个DataGrID.当我从网格中选择一条记录(即SelectedItem)时,我想在d出窗口的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,21,0" padding="0"> </Sdk:autocompletebox>
此属性在我的视图模型中并绑定到DataGrID:
public InvoicesDTO SelectedInvoice{ get { return _selectedInvoice; } set { SelectedInvoice = value; SelectedDomoText = SelectedInvoice.DemoText.Trim(); RaisePropertyChanged("SelectedInvoice"); }}解决方法 您不应在自动完成中同时使用函数SelectedText和SelectedItem.这是autocompletebox的一个错误…..更好的方法是在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 – Autocompletebox SelectedText Bug全部内容,希望文章能够帮你解决silverlight-4.0 – Autocompletebox SelectedText Bug所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)