從視圖模型(C#)對WPF中的TextBox設(shè)置焦點(diǎn)我有一個TextBox和一個Button在我看來?,F(xiàn)在,我在單擊按鈕時檢查一個條件,如果條件結(jié)果為false,則向用戶顯示消息,然后我必須將光標(biāo)設(shè)置為TextBox控制室。if (companyref == null){
var cs = new Lipper.Nelson.AdminClient.Main.Views.ContactPanels.CompanyAssociation();
MessageBox.Show("Company does not exist.", "Error", MessageBoxButton.OK,
MessageBoxImage.Exclamation);
cs.txtCompanyID.Focusable = true;
System.Windows.Input.Keyboard.Focus(cs.txtCompanyID);}上面的代碼在ViewModel中。這個CompanyAssociation視圖名。但是游標(biāo)沒有被設(shè)置在TextBox.XAML是:<igEditors:XamTextEditor Name="txtCompanyID"
KeyDown="xamTextEditorAllowOnlyNumeric_KeyDown"
ValueChanged="txtCompanyID_ValueChanged"
Text="{Binding Company.CompanyId,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"
Width="{Binding ActualWidth, ElementName=border}"
Grid.Column="1" Grid.Row="0"
VerticalAlignment="Top"
HorizontalAlignment="Stretch"
Margin="0,5,0,0"
IsEnabled="{Binding Path=IsEditable}"/><Button Template="{StaticResource buttonTemp1}"
Command="{Binding ContactCommand}"
CommandParameter="searchCompany"
Content="Search"
Width="80"
Grid.Row="0" Grid.Column="2"
VerticalAlignment="Top"
Margin="0"
HorizontalAlignment="Left"
IsEnabled="{Binding Path=IsEditable}"/>
從視圖模型(C#)對WPF中的TextBox設(shè)置焦點(diǎn)
幕布斯6054654
2019-06-28 17:02:00