我设置了1个文本框和1个组合框,在运行程序时,第一个焦点在文本框上,当我按Tab键聚焦在我得到的组合框中时:
InvalidOperationException: ‘validationTooltip’ name cannot be found in the name scope of ‘System.Windows.Controls.ToolTip’.`
为了帮助你在这里帮助我,我的XAML的一部分:
<Window.DataContext> <viewmodels:MainWindowviewmodel/> </Window.DataContext> <!-- Batch ID--> <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,65,0" TabIndex="1" Height="26" VerticalAlignment="Top" /> <!-- Product --> <Label Content="Product" Height="28" Margin="54,81,0" VerticalAlignment="Top" /> <ComboBox Name="cmbProduct" ItemsSource="{Binding Products}" DisplayMemberPath="ProductName" SelectedValuePath="ProductId" SelectedValue="{Binding SelecteProductId,ValidatesOnDataErrors=True}" Height="23" Margin="124,0" VerticalAlignment="Top" TabIndex="2" />
这是用于数据绑定组合框的ProductModel.cs:
public class ProductModel { public int ProductId {get;set;} public int ProductName {get;set;} public ProductModel(int prodId,string prodName) { ProductId = prodIdl; ProductName = prodName; } }
这是实现INotifyPropertyChanged和IDataErrorInfo的MainWindowviewmodel.cs:
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; } }
解决方法
>在项目中卸载/删除mahApps.重新构建您的项目,让我们看看您是否仍然遇到相同的错误.
1.1.如果问题仍然存在,请转到步骤2,如果不继续步骤1.2.
1.2.如果通过删除mahApps来解决问题,您可以选择其他布局包. :))或者如果你真的想使用mahApps.请忽略第一步. 2继续步骤no. 3
>如果问题仍然存在,请尝试在Visual Studio 2013中重新迭代您的解决方案.您可以下载here.如果您已经在使用VS2013,请继续执行步骤3.
>重新安装mahApps(确保已经删除旧mahApps的所有.dll和包).转到Package Manager控制台键:
安装包MahApps.Metro -Pre
>做需要使用mahApps的东西.关闭窗口标签之前即. < / Controls:MetroWindow> ;,确保你有这个:
<Window.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,/MahApps.Metro;component/Styles/Colors.xaml" /> <ResourceDictionary Source="pack://application:,/MahApps.Metro;component/Styles/Fonts.xaml" /> <ResourceDictionary Source="pack://application:,/MahApps.Metro;component/Styles/Controls.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Window.Resources>
>重新构建您的应用程序,让我们看看您有什么.
简短回答:
清除卸载mahApps(即删除所有DLL和包)将解决问题.在干净地卸载mahApps之后,如果您想再试一次,可以通过NuGet或通过Package Manager安装全新的mahApps.按照说明here.如果全部失败,请更新您的VS,然后再次尝试更新mahApps.
希望有所帮助!