首页 \ 问答 \ 绑定后的ObservableCollection更新(ObservableCollection update after binding)

绑定后的ObservableCollection更新(ObservableCollection update after binding)

我有一个ObservbleCollection绑定到列表框。 在我将集合作为列表的ItemsSource后,我无法更新我的集合。 如果我更新它,程序关闭(没有任何崩溃)。

代码:
我上课了:

class MyFile
{
    String FileName {get; set;}
    ImageSource Ico {get; set;}
}

然后在约束器中运行代码(在InitializeComponents之后)

ObservableCollection<MyFile> filesList = new ObservableCollection<MyFile>();
filesList.Add(new MyFile { Name = "bar.doc", Ico = null } // Work Fine
filesList.Add(new MyFile { Name = "foo.txt", Ico = null } // Work Fine
files.ItemsSource = filesList; 
filesList.Add(new MyFile { Name = "try.txt", Ico = null } // EXIT FROM PROGRAM

我的课程有什么问题?

编辑
刚刚使用null测试它而不是GetIcon


I have an ObservbleCollection with binding to listbox. After I put the collection as ItemsSource of the list, I cannot update my collection. If I update it, the program close (without any crash).

The Code:
I have the class:

class MyFile
{
    String FileName {get; set;}
    ImageSource Ico {get; set;}
}

Then run the code in the constractor (after InitializeComponents)

ObservableCollection<MyFile> filesList = new ObservableCollection<MyFile>();
filesList.Add(new MyFile { Name = "bar.doc", Ico = null } // Work Fine
filesList.Add(new MyFile { Name = "foo.txt", Ico = null } // Work Fine
files.ItemsSource = filesList; 
filesList.Add(new MyFile { Name = "try.txt", Ico = null } // EXIT FROM PROGRAM

What's wrong in my program?

Edit
Just tested it with null instead GetIcon


原文:https://stackoverflow.com/questions/15729739
更新时间:2024-04-18 10:04

最满意答案

现在您已经修改了要显示的代码;

public static void Foo(this Car car, Bike bike)
{
    car.Foo(bike);//Success...
}

你所做的就是创造一个具有讽刺意味的StackOverflowException。 这个方法现在只是递归调用自身,而不是在Car实现Foo

提示:获取ReSharper的副本 - 它会在这行代码上放置一个漂亮的圆圈箭头图标,以显示正在发生的事情,而无需实际编译或运行它。 :-)


Now that you've modified the code to show;

public static void Foo(this Car car, Bike bike)
{
    car.Foo(bike);//Success...
}

All you've done is create an ironic StackOverflowException. This method is now just calling itself recursively, not the implementation of Foo in Car.

TIP: Get yourself a copy of ReSharper - it'll put a nice circle-arrow icon on this line of code to show you what's going on without actually needing to compile or run it. :-)

相关问答

更多
  • 你可以通过中间类来完成。 编译器本身不会进行两次隐式转换,因此您必须进行一次显式转换,然后编译器将找出第二个。 问题是,使用隐式强制类型转换,您必须强制转换为您声明强制转换的类型,并且不能继承密封类,如'int'。 所以,它根本不优雅。 扩展方法可能更优雅。 如果您在下面声明该类,则可以执行以下操作: byte[] y = (Qwerty)3; int x = (Qwerty) y; public class Qwerty { private int _x; ...
  • 您不能通过扩展方法重载操作符。 最好使用扩展方法: public static MembershipUser ConvertToMembershipUser(this User user) { return new MembershipUser("SimplyMembershipProvider", user.UserName, user.UserId, ...
  • 不,你不能使用显式,但你可以这样做: class ClassThatOnlyTakesBoolsAndUIntsAsArguments { public: void Method(bool arg1); void Method(unsigned int arg1); // Below just an example showing how to do the same thing with more arguments void MethodWithMoreParms(bool arg1, ...
  • 现在您已经修改了要显示的代码; public static void Foo(this Car car, Bike bike) { car.Foo(bike);//Success... } 你所做的就是创造一个具有讽刺意味的StackOverflowException。 这个方法现在只是递归调用自身,而不是在Car实现Foo 。 提示:获取ReSharper的副本 - 它会在这行代码上放置一个漂亮的圆圈箭头图标,以显示正在发生的事情,而无需实际编译或运行它。 :-) Now that you've ...
  • 因为不调用转换运算符。 请参阅: http : //msdn.microsoft.com/en-us/library/cscsdfbt(v = VS.100).aspx 使用(演员)。 as does not invoke conversion operators. See: http://msdn.microsoft.com/en-us/library/cscsdfbt(v=VS.100).aspx Use a (cast).
  • 想象一下,你正在寻找一个程序中的错误 数千行代码 10位撰稿人,其中5位不再提供 字符串和数字之间的数百次自动转换 通过这些自动转换,您可以为错误提供不必要的广泛空间。 另一方面,通过禁止自动转换,您可以强制程序员在他们放置它们的每个地方进行思考 : 我需要转换。 为什么? 我真的使用最适合的任务数据类型? 输入是否包含会导致转换失败的字符? 如果输入为空,空字符串或仅包含空格,该怎么办? 如果输入具有正确的字符,但是太长,该怎么办? 如果输入超出目标类型允许的值范围,该怎么办? 如果客户端的计算机切换到使 ...
  • 我通常使用双重否定(这意味着应用逻辑NOT运算符两次)进行显式布尔转换: !!v 例子: !!'test' // true !!'' // false !!0 // false !!1 // true !!null // false !!undefined // false !!NaN // false 或者, Boolean(v)也可以工作。 I usually use double negation (which means applying the logical NOT operator twi ...
  • 显然,这是不可能的。 如此相关SO帖子1和SO帖子2中所述 ,不可能自动绕过证书例外。 您必须手动添加证书,有关其他信息,请参阅超级用户帖子 。 希望这可以帮助。 Apparently, this is not possible. As stated in this related SO post 1 and SO post 2, it is not possible to bypass certificate exception automatically. You have to add manuall ...
  • 是的,这只是明确指出类型必须是CHA.ByteString 。 这确实(本身) 不会产生任何类型的转换,它只是编译器(和/或读者)的一个提示,即res必须具有这种类型。 这些类型的本地注释是当一个值是由多态结果函数产生的 ,并且只有具有多态参数的函数消耗时才需要的。 一个简单的例子: f :: Int -> Int f = fromEnum . toEnum 在这里, toEnum将整数转换为任意的可枚举类型 - 例如可以是Char 。 无论您选择什么类型, fromEnum都能够将其转换回来...... ...
  • 简单修复: var unbilled = from a in allAudits join b in billedAudits on a.k equals b.k into combined from c in combined.DefaultIfEmpty() where c == null select a.k; 此外,其他两个查询似乎不需要匿名结构,最后一个可以大大简化: public IEnumerable UnbilledAudi ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)