observablecollection

Bind Usercontrol contained in a ObservableCollection<CustomClass> in a WrapPanel

大城市里の小女人 提交于 2019-12-11 09:31:43
问题 I have a class defined this way: public class CustomClass { string Name; int Age; Usercontrol usercontrol; } where Usercontrol is a visual element that I want to insert in a WrapPanel. CustomClass is organized in a static ObservableCollection. public static class CollectionClass { public static ObservableCollection<CustomClass> MyCollection = new ObservableCollection<CustomClass>(); } I am looking to bind the usercontrol property of the CustomClass in the collection to be visualized in the

Add initially missing collection items via binding

别等时光非礼了梦想. 提交于 2019-12-11 08:46:47
问题 Given: class StringRecord : INotifyPropertyChanged { public string Key { get; set; } // real INPC implementation is omitted public string Value { get; set; } // real INPC implementation is omitted ... } class Container { public ObservableKeyedCollection<string, StringRecord> Params { get; set; } ... { The ObservableKeyedCollection is the one found here. A TextBox is bound to one of the collection items (DataContext is inherited): <TextBox Text="{Binding Params[APN_HOST].Value}"/> When I

Is it possible to return a read-only ObservableCollection that the caller can't modify?

前提是你 提交于 2019-12-11 08:06:54
问题 Consider the following code: public ObservableCollection<Message> Messages { get { return new ObservableCollection<Message>(); } } Is there anything I can do to prevent the caller code from adding/removing/changing items? EDIT: Sorry, everyone, I just noticed it's a dupe, but the accepted answer is wrong. 回答1: What about using ReadOnlyObservableCollection Code would be: public ReadOnlyObservableCollection<Message> Messages { get { return new ReadOnlyObservableCollection<Message>(new

Adding Custom Class as TreeViewItem to TreeView WPF

瘦欲@ 提交于 2019-12-11 07:31:43
问题 I have scenario where my TreeView look like below: MainParent .>-Parent ...>--Child1 ...>--Child2 ...>--Child3 ...>--Child4 ...>--Child5 ......> Child1_Of_Child5 ...........>Child1(Child1_Of_Child5) ...........>Child2(Child1_Of_Child5) ......> Child2_of_Child5 ...........>Child1(Child2_Of_Child5) ...........>Child2(Child2_Of_Child5) I am able to bind ObservableCollection till Child1/Child2/../Child5 using HierarchicalDataTemplate. Though I am able to add Child1_Of_Child5 to Child5

Efficient way of updating a collection from another collection

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 07:28:21
问题 Is the following way of updating an ObservableCollection from another one (both based on the same class) good enough or it better to be done in another way (or just to be improved)? foreach (MyEntity c in collection2) { collection1.Where(p => p.EntID == c.EntID).FirstOrDefault().Field1 = c.Field1; collection1.Where(p => p.EntID == c.EntID).FirstOrDefault().Field2 = c.Field2; ... collection1.Where(p => p.EntID == c.EntID).FirstOrDefault().FieldN = c.FieldN; } EntID is the primary key. (Under

Listview TwoWay Binding With ObservableCollection

混江龙づ霸主 提交于 2019-12-11 07:02:59
问题 :::::::::: ObservableCollection :::::::::: ObservableCollection<Friend> Friends = new ObservableCollection<Friend> ( ); :::::::::: InitializeFriends :::::::::: private void InitializeFriends ( ) { JsonObject _JsonObject = Process . FacebookClient . Get ( "/me/friends" ) as JsonObject; if ( _JsonObject != null ) { JsonArray _JsonArray = _JsonObject [ "data" ] as JsonArray; foreach ( JsonObject Friend in _JsonArray ) { Friends . Add ( new Friend ( ) { Name = Friend [ "name" ] . ToString ( ) } )

ObservableCollection of open generic type

﹥>﹥吖頭↗ 提交于 2019-12-11 06:44:48
问题 I have an interface public interface IImageFilter<TIn, TOut> { // Properties TIn Input { get; set; } string Name { get; set; } Guid Guid { get; set; } TOut Process(TIn frame); } and I needed an observable collection of objects that implement the interface. private ObservableCollection<IImageFilter<T, U>> _imageFilters; the object that i pass to the collection can be IImageFilter<string, string> IImageFilter<string, int> IImageFilter<int, double> How do it declare the _imageFilters? what's the

WPF: Binding to ObservableCollection in ControlTemplate is not updated

徘徊边缘 提交于 2019-12-11 06:06:58
问题 I created a ControlTemplate for my custom control MyControl . MyControl derives from System.Windows.Controls.Control and defines the following property public ObservableCollection<MyControl> Children{ get; protected set; } . To display the nested child controls I am using an ItemsControl ( StackPanel ) which is surrounded by a GroupBox . If there are no child controls, I want to hide the GroupBox . Everything works fine on application startup: The group box and child controls are shown if the

Linq List Ranking in C#

*爱你&永不变心* 提交于 2019-12-11 05:14:26
问题 I have the below list which consist of a list of names and scores. The scores I got from using linq to get the sum of points for the list of peope: Name Score Ed 5 John 6 Sara 7 Dean 3 Nora 4 So i was able to group the list and make the sums, but now I am trying to rank these based on the score. So I am trying to get the below list: Rank Name Score 1 Sara 7 2 John 6 3 Ed 5 4 Nora 4 5 Dean 3 But the linq code I am using doesn't seem to be getting the right ranks for me. Here's my code for

Refreshing UI after update to a ListBox-bound collection

旧街凉风 提交于 2019-12-11 04:41:56
问题 I am trying to visually show that an item (a BitmapImage in my case) has been added to a collection in a ListBox using WPF/MVVM. To give some background, I'm capturing streaming video with a capture card, and I'm taking still images while the video is streaming. These images are captured by clicking the "Still Image" button on the UI. After capturing an image, I would like for a thumbnail of said image in a separate panel on the UI. I understand what needs to be done to do this, but I can't