- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 ObservableCollection 项目,我需要能够更新它并仍然使用 ICollectionView 来表示数据。
以下是相关代码:
private ObservableCollection<Hero> heroesDBHeroes;
public ObservableCollection<Hero> HeroesDBHeroes
{
get
{
return heroesDBHeroes;
}
set
{
heroesDBHeroes = value;
OnPropertyChanged("HeroesDBHeroes");
}
}
private void HeroesDBAddHeroes()
{
if(HeroesDBHeroes != null)
{
HeroesDBHeroes.Clear();
}
HeroesDBHeroes = Hero.GetAllHeroes();
HeroesDBFilteredHeroes = new ListCollectionView(HeroesDBHeroes);
HeroesDBFilteredHeroes.Filter = new Predicate<object>(HeroesDBFilterHeroes);
HeroesDBFilteredHeroes.Refresh();
OnPropertyChanged("HeroesDBFilteredHeroes");
}
这是 CollectionView 及其过滤器:
public CollectionView HeroesDBFilteredHeroes { get; set; }
public bool HeroesDBFilterHeroes(object item)
{
Hero h = item as Hero;
bool ID, Name, GoldMinimum, GoldMaximum, PlatinumMinimum, PlatinumMaximum, DBTag, ReleaseDateStart, ReleaseDateEnd, Available, Sale, Featured, New, F2P, Homepage, Thumbnail, FeaturedThumbnail, ShortDescription, Description;
ID = Name = GoldMinimum = GoldMaximum = PlatinumMinimum = PlatinumMaximum = DBTag = ReleaseDateStart = ReleaseDateEnd = Available = Sale = Featured = New = F2P = Homepage = Thumbnail = FeaturedThumbnail = ShortDescription = Description = false;
if (h == null)
{
return false;
}
if (HeroesDBFilterID == null || HeroesDBFilterID == h.ID)
{
ID = true;
}
if (HeroesDBFilterName == "" || h.Name.IndexOf(HeroesDBFilterName, 0, StringComparison.CurrentCultureIgnoreCase) != -1)
{
Name = true;
}
if (HeroesDBFilterGoldMinimum == null || HeroesDBFilterGoldMinimum <= h.Gold)
{
GoldMinimum = true;
}
if (HeroesDBFilterGoldMaximum == null || HeroesDBFilterGoldMaximum >= h.Gold)
{
GoldMaximum = true;
}
if (HeroesDBFilterPlatinumMinimum == null || HeroesDBFilterPlatinumMinimum <= h.Platinum)
{
PlatinumMinimum = true;
}
if (HeroesDBFilterPlatinumMaximum == null || HeroesDBFilterPlatinumMaximum >= h.Platinum)
{
PlatinumMaximum = true;
}
if (HeroesDBFilterDBTag == "" || h.DBTag.IndexOf(HeroesDBFilterDBTag, 0, StringComparison.CurrentCultureIgnoreCase) != -1)
{
DBTag = true;
}
if (HeroesDBFilterReleaseDateStart == null || HeroesDBFilterReleaseDateStart <= h.ReleaseDate)
{
ReleaseDateStart = true;
}
if (HeroesDBFilterReleaseDateEnd == null || HeroesDBFilterReleaseDateEnd >= h.ReleaseDate)
{
ReleaseDateEnd = true;
}
switch(HeroesDBFilterAvailable)
{
case 0:
Available = true;
break;
case 1:
if(h.Available == true)
{
Available = true;
}
break;
case 2:
if (h.Available == false)
{
Available = true;
}
break;
}
switch (HeroesDBFilterSale)
{
case 0:
Sale = true;
break;
case 1:
if (h.Sale == true)
{
Sale = true;
}
break;
case 2:
if (h.Sale == false)
{
Sale = true;
}
break;
}
switch (HeroesDBFilterFeatured)
{
case 0:
Featured = true;
break;
case 1:
if (h.Featured == true)
{
Featured = true;
}
break;
case 2:
if (h.Featured == false)
{
Featured = true;
}
break;
}
switch (HeroesDBFilterNew)
{
case 0:
New = true;
break;
case 1:
if (h.NewTag == true)
{
New = true;
}
break;
case 2:
if (h.NewTag == false)
{
New = true;
}
break;
}
switch (HeroesDBFilterF2P)
{
case 0:
F2P = true;
break;
case 1:
if (h.F2P == true)
{
F2P = true;
}
break;
case 2:
if (h.F2P == false)
{
F2P = true;
}
break;
}
switch (HeroesDBFilterHomepage)
{
case 0:
Homepage = true;
break;
case 1:
if (h.Homepage == true)
{
Homepage = true;
}
break;
case 2:
if (h.Homepage == false)
{
Homepage = true;
}
break;
}
switch (HeroesDBFilterThumbnail)
{
case 0:
Thumbnail = true;
break;
case 1:
if (h.ThumbnailImage.Count<byte>() >= 5)
{
Thumbnail = true;
}
break;
case 2:
if (h.ThumbnailImage.Count<byte>() < 5)
{
Thumbnail = true;
}
break;
}
switch (HeroesDBFilterFeaturedThumbnail)
{
case 0:
FeaturedThumbnail = true;
break;
case 1:
if (h.FeaturedThumbnailImage.Count<byte>() >= 5)
{
FeaturedThumbnail = true;
}
break;
case 2:
if (h.FeaturedThumbnailImage.Count<byte>() < 5)
{
FeaturedThumbnail = true;
}
break;
}
if (HeroesDBFilterShortDescription == "" || h.ShortDescription.IndexOf(HeroesDBFilterShortDescription, 0, StringComparison.CurrentCultureIgnoreCase) != -1)
{
ShortDescription = true;
}
if (HeroesDBFilterDescription == "" || h.Description.IndexOf(HeroesDBFilterDescription, 0, StringComparison.CurrentCultureIgnoreCase) != -1)
{
Description = true;
}
return ID && Name && GoldMinimum && GoldMaximum && PlatinumMinimum && PlatinumMaximum && DBTag && ReleaseDateStart && ReleaseDateEnd && Available && Sale && Featured && New && F2P && Homepage && Thumbnail && FeaturedThumbnail && ShortDescription && Description;
}
我在以下代码片段中收到以下错误:
An unhandled exception of type 'System.NotSupportedException' occurred in PresentationFramework.dll
Additional information: This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread.
private ICommand heroesDBAddEntry;
public ICommand HeroesDBAddEntry
{
get
{
if (heroesDBAddEntry == null)
{
heroesDBAddEntry = new RelayCommand(HeroesDBAddEntryEx, null);
}
return heroesDBAddEntry;
}
}
private void HeroesDBAddEntryEx(object p)
{
if (HeroesDBUpdateID != null)
{
HeroesDBUpdateEntryEx();
return;
}
int x;
var db = new SQLiteDatabase();
string query, changesQuery;
query = "INSERT INTO Heroes (Name,Description,ShortDescription,Gold,Platinum,DBTag,ReleaseDate,Available,Sale,Featured,NewTag,F2P,Homepage,ThumbnailImage,ThumbnailImageName," +
"FeaturedThumbnailImage,FeaturedThumbnailImageName) ";
query += "VALUES ('" + HeroesDBName.Replace("'", "''") + "','" + HeroesDBDescription.Replace("'", "''") + "','" + HeroesDBShortDescription.Replace("'", "''") + "'," +
HeroesDBGold + "," + HeroesDBPlatinum + ",'" + HeroesDBDBTag.Replace("'", "''") + "','" + HeroesDBReleaseDate.Date.ToString("yyyy-MM-dd") + "'," +
Convert.ToInt32(HeroesDBAvailable) + "," + Convert.ToInt32(HeroesDBSale) + "," + Convert.ToInt32(HeroesDBFeatured) + "," + Convert.ToInt32(HeroesDBNewTag) + "," +
Convert.ToInt32(HeroesDBF2P) + "," + Convert.ToInt32(HeroesDBHomepage) + ",'" + Convert.ToBase64String(HeroesDBThumbnailImage) + "','" +
HeroesDBThumbnailPath.Replace("'", "''") + "','" + Convert.ToBase64String(HeroesDBFeaturedThumbnailImage) + "','" + HeroesDBFeaturedThumbnailPath.Replace("'", "''") + "'); ";
changesQuery = "INSERT INTO Heroes_Changes (HeroID,Action,TimeStamp,User,Name,Description,ShortDescription,Gold,Platinum,DBTag,ReleaseDate,Available,Sale,Featured,NewTag,F2P," +
"Homepage,ThumbnailImage,ThumbnailImageName,FeaturedThumbnailImage,FeaturedThumbnailImageName) ";
changesQuery += "VALUES (" + HeroesDBNextID + ",'" + "INSERT" + "','" + DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "','" + Environment.UserName + "','" +
HeroesDBName.Replace("'", "''") + "','" + HeroesDBDescription.Replace("'", "''") + "','" + HeroesDBShortDescription.Replace("'", "''") + "'," +
HeroesDBGold + "," + HeroesDBPlatinum + ",'" + HeroesDBDBTag.Replace("'", "''") + "','" + HeroesDBReleaseDate.Date.ToString("yyyy-MM-dd") + "'," +
Convert.ToInt32(HeroesDBAvailable) + "," + Convert.ToInt32(HeroesDBSale) + "," + Convert.ToInt32(HeroesDBFeatured) + "," + Convert.ToInt32(HeroesDBNewTag) + "," +
Convert.ToInt32(HeroesDBF2P) + "," + Convert.ToInt32(HeroesDBHomepage) + ",'" + Convert.ToBase64String(HeroesDBThumbnailImage) + "','" +
HeroesDBThumbnailPath.Replace("'", "''") + "','" + Convert.ToBase64String(HeroesDBFeaturedThumbnailImage) + "','" + HeroesDBFeaturedThumbnailPath.Replace("'", "''") + "'); ";
try
{
x = db.ExecuteNonQuery(query);
HeroesDBStatus = x + " Record(s) Added.";
x = db.ExecuteNonQuery(changesQuery);
}
catch(Exception err)
{
System.Windows.Forms.MessageBox.Show(err.Message);
}
HeroesDBHeroes.Add(new Hero(
HID: HeroesDBNextID,
HName: HeroesDBName,
HDescription: HeroesDBDescription,
HShortDescription: HeroesDBShortDescription,
HGold: HeroesDBGold,
HPlatinum: HeroesDBPlatinum,
HDBTag: HeroesDBDBTag,
HReleaseDate: HeroesDBReleaseDate,
HAvailable: HeroesDBAvailable,
HSale: HeroesDBSale,
HFeatured: HeroesDBFeatured,
HNewTag: HeroesDBNewTag,
HF2P: HeroesDBF2P,
HHomepage: HeroesDBHomepage,
HThumbnailImage: HeroesDBThumbnailImage,
HThumbnailImageName: HeroesDBThumbnailPath,
HFeaturedThumbnailImage: HeroesDBFeaturedThumbnailImage,
HFeaturedThumbnailImageName: HeroesDBFeaturedThumbnailPath,
HForce: true
));
HeroesDBNextID++;
HeroesDBName = "";
HeroesDBDescription = "";
HeroesDBShortDescription = "";
HeroesDBGold = 0;
HeroesDBPlatinum = 0;
HeroesDBDBTag = "";
HeroesDBReleaseDate = DateTime.Today;
HeroesDBAvailable = false;
HeroesDBSale = false;
HeroesDBFeatured = false;
HeroesDBNewTag = false;
HeroesDBF2P = false;
HeroesDBHomepage = false;
HeroesDBThumbnailImage = new byte[] { 0x00 };
HeroesDBThumbnailPath = "";
HeroesDBFeaturedThumbnailImage = new byte[] { 0x00 };
HeroesDBFeaturedThumbnailPath = "";
HeroesDBUpdateID = null;
}
错误发生在 HeroesDB.Add(...) 行,就在 try catch 之后。
我尝试了很多方法,但没有一个起作用。
我尝试使用另一个 ObservableCollection 作为过滤列表并过滤它,但它仍然给我一个错误。我尝试过使用其他人发布的从 Google 第一页获取的 MTObservableCollection 和 AsyncObservableCollection,但它们也在其他方面造成了困惑。
我该如何解决这个问题?我需要能够进行过滤,我需要它们的集合,并且当源发生更改时,我需要立即在应用程序中查看这些更改。
最佳答案
您是否尝试过包装所有将过滤器设置为调用 WPF 调度程序的代码?
通常,如果在与 UI 线程不同的线程的代码中修改了绑定(bind)到 View 的集合,则必须执行此操作。
Application.Current.Dispatcher.BeginInvoke(
DispatcherPriority.Background,
new Action(() => {
HeroesDBAddHeroes();
}));
关于c# - 错误: This type of CollectionView does not support changes to its SourceCollection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33808346/
我收到多行错误,指出它有重复的类 Duplicate class android.support.v4.accessibilityservice.AccessibilityServiceInfoCom
我的项目昨天运行良好,今天却出现以下错误。请帮忙。 出了什么问题:无法解析配置“:app:debugCompileClasspath”的所有文件。 Could not find support-v4.
错误:配置项目“:app”时出现问题。 Could not find support-v4.jar (com.android.support:support-v4:24.0.0). Searched
我正在使用 react-native-webrtc 运行示例应用程序模块。我正在尝试在 android 中运行该应用程序,但出现这样的错误... * What went wrong: A probl
错误:配置项目“:app”时出现问题。 Could not find support-v4.jar (com.android.support:support-v4:24.0.0). Searched
我克隆了我的项目并使用 Android studio 打开,但构建失败并出现以下错误并且同一个项目在其他项目上运行良好。 出了什么问题:无法解析配置“:app:flavorUnsignedReleas
我正在运行示例应用程序......我正在使用 this模块.....但是我收到这样的错误... FAILURE: Build failed with an exception. * What went
我有一个 Ionic 项目,在升级到 OSx Mojave 后,出于某种原因不再构建。 该项目基于 Ionic 3 构建。 我有 Cordova CLI 7.0.0 当我运行时 ionic cordo
我有一个 Ionic 项目,在升级到 OSx Mojave 后,出于某种原因不再构建。 该项目基于 Ionic 3 构建。 我有 Cordova CLI 7.0.0 当我运行时 ionic cordo
添加 Android 平台(ionic cordova platform add android)后,我构建了我的 Ionic 项目(ionic cordova build android),但出现错
这个问题在这里已经有了答案: Manifest merger failed : Attribute application@appComponentFactory - Androidx (14 个答
关于我的 Gradle 文件中的以下“complie”: dependencies { compile 'com.android.support:support-v4:25.3.1' }
有些困惑。 我想更频繁地使用@supports 但是...我不关心浏览器如何看待它。希望您能说清楚,如果可以的话谢谢您。 如果浏览器本身不理解@supports,它如何计算@support 'not'
我刚刚升级到 Dart 2 和最新版本的 Flutter,现在我无法构建我的应用程序。我在互联网上环顾四周,但仍然不明白为什么会发生这种情况。 我得到的错误是: FAILURE: Build fail
我正在学习 Firebase,但由于以下错误而陷入困境: Error:Failed to resolve: com.android.support:customtabs:25.4.0 Error:Fa
我在构建本周时出于某种原因尝试使用Cordova进行项目时遇到问题: cordova build android gradle获取com.android.support:support alpha而不
对应的androidx是什么com.android.support:support-compat 的图书馆实现push notifications ? 他们说here它是 androidx 的一部分,
我正在尝试为我的应用设置插桩单元测试。并且我已根据以下开发者站点链接添加了依赖项。 https://developer.android.com/training/testing/unit-testin
当我想使用 Proguard 规则生成签名的 APK(发布)时,我收到了以下错误消息: Cannot find a version of 'com.android.support:support-an
这个问题在这里已经有了答案: Failed to resolve: com.android.support:appcompat-v7:26.0.0 (14 个答案) Failed to resolv
我是一名优秀的程序员,十分优秀!