我正在使用这样的转换器:
public class BreedConverter : IValueConverter
{
static ObservableCollection<Breed_> Breeds = Breed_.GetBreeds();
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value != null && Breeds.Count > 0)
{
short breedID = (short)value;
Breed_ breed = Breeds.Single(s => s.BreedID == breedID);
return (string)breed.Breed;
}
else
return "";
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
“品种”集合是从SQL Server数据库中检索的。我想检索一次,然后使用它进行转换。我不想每次都需要转换时进入数据库。
是否有更好的方法可以做到这一点,例如ResourceDictionary(由于我仍然是菜鸟,所以在这种情况下我不知道如何使用它?)>
我正在使用这样的转换器:public class BreedConverter:IValueConverter {static ObservableCollection
这就是我能够开始工作的地方。正如@Darthchai所提到的,我已经在类/窗口中创建了集合。但是,我无法弄清楚如何使用INotifyPropertyChanged让特定的TextBlock知道进行转换。毕竟我是菜鸟。 :)我能做的-我不知道这是否是正确的方法-是使用TextBlock的Loaded事件进行转换的。这是代码: