I have a problem checking ComboBox using IDataErrorInfo .
I set 1 text box and 1 combobox, after starting the program, the first focus is in the text box, when I click on the tab to focus in the drop-down list that I get:
InvalidOperationException: The name "validationTooltip" cannot be found in the namespace "System.Windows.Controls.ToolTip".
To help you here help in some part of my XAML:
<Window.DataContext> <ViewModels:MainWindowViewModel/> </Window.DataContext> <Label Content="Batch ID" Height="28" Margin="64,52,191,0" VerticalAlignment="Top" /> <TextBox Name="txtBatchId" Text="{Binding BatchId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Margin="124,52,65,0" TabIndex="1" Height="26" VerticalAlignment="Top" /> <Label Content="Product" Height="28" Margin="54,81,191,0" VerticalAlignment="Top" /> <ComboBox Name="cmbProduct" ItemsSource="{Binding Products}" DisplayMemberPath="ProductName" SelectedValuePath="ProductId" SelectedValue="{Binding SelecteProductId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Height="23" Margin="124,81,65,0" VerticalAlignment="Top" TabIndex="2" />
Here is the ProductModel.cs that is used in the data binding binding:
public class ProductModel { public int ProductId {get;set;} public int ProductName {get;set;} public ProductModel(int prodId, string prodName) { ProductId = prodIdl; ProductName = prodName; } }
And here is MainWindowViewModel.cs , which implements INotifyPropertyChanged and IDataErrorInfo:
public class MainWindowViewModel : ViewModelBase, IDataErrorInfo { private string _batchId; public string BatchId { get { return _batchId; } set { _batchId = value; OnPropertyChanged("BatchId"); } } private ObservableCollection<Product> _products = new ObservableCollection<Product>(); public IEnumerable<Product> Products { get { return _products; } } private string _selectedProductId; public string SelectedProductId { get { return _selectedProductId; } set { _selectedProductId = value; OnPropertyChanged("SelectedProductId"); } } public void PopulateProduct() { .... } public MainWindowViewModel() { PopulateProduct(); } public string this[string columnName] { get { string result = string.Empty; switch (columnName) { case "SelectedProductId": if (SelectedProductId == null || SelectedProductId == "0") { result = "Please select a product"; } break; case "BatchId": if (string.IsNullOrWhitespace(BatchId)) { result = "Please input batch id"; } break; } return result; } } public string Error { get; private set; } }
Any help would be greatly appreciated. Please let me know everything that I can add from my end to make it more understandable.