绑定后的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测试它而不是GetIconI 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
最满意答案
现在您已经修改了要显示的代码;
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
inCar
.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; ...
-
扩展方法和显式投射(Extension method and Explicit casting)[2021-08-22]
您不能通过扩展方法重载操作符。 最好使用扩展方法: public static MembershipUser ConvertToMembershipUser(this User user) { return new MembershipUser("SimplyMembershipProvider", user.UserName, user.UserId, ... -
您可以使用关键字显式来阻止方法参数的自动转换吗?(Can you use keyword explicit to prevent automatic conversion of method parameters?)[2022-03-05]
不,你不能使用显式,但你可以这样做: 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, ... -
为什么扩展方法会绕过显式转换的需要?(Why does an extension method bypass the need for explicit conversion?)[2021-11-15]
现在您已经修改了要显示的代码; 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).
-
为什么我们需要显式转换(Why do we need Explicit Conversion)[2021-08-06]
想象一下,你正在寻找一个程序中的错误 数千行代码 10位撰稿人,其中5位不再提供 字符串和数字之间的数百次自动转换 通过这些自动转换,您可以为错误提供不必要的广泛空间。 另一方面,通过禁止自动转换,您可以强制程序员在他们放置它们的每个地方进行思考 : 我需要转换。 为什么? 我真的使用最适合的任务数据类型? 输入是否包含会导致转换失败的字符? 如果输入为空,空字符串或仅包含空格,该怎么办? 如果输入具有正确的字符,但是太长,该怎么办? 如果输入超出目标类型允许的值范围,该怎么办? 如果客户端的计算机切换到使 ... -
显式布尔转换(Explicit boolean conversion)[2023-02-11]
我通常使用双重否定(这意味着应用逻辑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 ...
-
显式类型转换?(Explicit type conversion?)[2024-03-16]
是的,这只是明确指出类型必须是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 ...