observablecollection

Reusing Binding Collections for WPF

回眸只為那壹抹淺笑 提交于 2019-12-10 15:59:44
问题 I am working on a WPF app using the MVVM patterm, which I am learning. It uses EF4. I am trying to use a similar tabbed document interface style; several combo boxes on these tabs have the same items sources (from a sql db). Since this data almost never changes, it seemed like a good idea to make a repository object to get them when the app starts, and just reuse them for each viewmodel. For whatever reason though, even though I use new in the constructors, the lists are connected. If I set a

Check if a ObservableCollection, and if so display an alternative xaml!

ε祈祈猫儿з 提交于 2019-12-10 14:19:47
问题 I have a ListView with a binding to a ObservableCollection . Further I am listing out all items in the ObservableCollection . Now, Is there a good way to check if the ObservableCollection is empty, and the display an alternative xaml? 回答1: You can use the HasItems dependency property of the ListView. With a trigger, when the property is false, you can change the ControlTemplate. Here is as example: <ListView ItemsSource="{Binding Items}"> <ListView.Style> <Style TargetType="{x:Type ListView}"

Changes in ObservableCollection do not update ListView

微笑、不失礼 提交于 2019-12-10 13:01:45
问题 I have been reading all the related articles here in the board but I still can't solve my problem that I have when binding an ObservableCollection to a ListView. I have a CLogEntry model class which basically wraps a string. /// Model of LogEntry public class CLogEntry:INotifyPropertyChanged { /// Fields private string _logEntry; /// Property public string LogEntry { get { return _logEntry; } set { _logEntry = value; RaisePropertyChanged("LogEntry"); } } /// PropertyChanged event handler

Fill observableCollection directly from sql server

此生再无相见时 提交于 2019-12-10 12:08:00
问题 I would like to know if there is any way to fill ObservableCollection directly from SQL server. Currently I am loading my data into DataTable (using sqlDataAdapter) and do a conversion to ObservableCollection manually and it very inefficient. How it can be done? 回答1: OK, I have found a way to do this: It can be done using SqlDataReader. public ObservableCollection<DataItem> LoadCategoriesData() { Command = new SqlCommand(StoredProcedure, Connection); Command.CommandType = CommandType

C# - WPF Reverse binded ObservableCollection in XAML

血红的双手。 提交于 2019-12-10 10:35:30
问题 I have a ObservableCollection which is binded as ItemSource to my ComboBox. It's a ComboBox which shows you your changes which you've done. My Problem is now, that the newest Change is displayed on the bottom of the list. I tried to reverse it in the property, but when I return ComboboxName.Reverse() I get an IEnumerable back. I also don't want to make a 2nd collection with the reversed data. An other way would be to solve this in XAML. Does someone have an idea how I can do that? I found

Bind ObservableCollection to a DataGrid after assigning new value

谁说胖子不能爱 提交于 2019-12-10 10:34:28
问题 It seems to be a simple problem, but I can't get it to work. I have a UserControl with the following property: public ObservableCollection<HL7Message> source {get; set;} And the following Binding: <data:DataGrid x:Name="dgMessages" Grid.Row="2" AutoGenerateColumns="True" ItemsSource="{Binding source}" ></data:DataGrid> from a parent UserControl I set the value upon a button click: messagesGrid.source = src; //messagesGrid is the name of the UserCntrol above I'm expecting my DataGrid to be

Multiple Views of Observable Collection

强颜欢笑 提交于 2019-12-10 09:23:49
问题 I've been working on this problem for a while and I'm clearly missing something... I create, populate and bind an observable collection like so: Dim _ObservableWEI As New ObservableWEI ... _ObservableWEI.Add(New WEI() With {.WEInum = 1, .WEIvalue = 1}) _ObservableWEI.Add(New WEI() With {.WEInum = 2, .WEIvalue = 0}) _ObservableWEI.Add(New WEI() With {.WEInum = 3, .WEIvalue = 2}) ... lbxAll.ItemsSource = _ObservableWEI Which is fine. I now need a second listbox containing a filtered version of

Replacement for ObservableCollection?

。_饼干妹妹 提交于 2019-12-09 19:19:21
问题 I'm looking for a replacement for ObservableCollection that is thread-safe, raises events on the UI thread and preferably has an AddRange method. I've seen a few implementations posted here and elsewhere, but I'd prefer an implementation that has been tested and validated and that I won't have to maintain myself. So can anyone point me to such a replacement, preferable available via NuGet? 回答1: For thread safe collections check the System.Collections.Concurrent namespace. ConcurrentStack has

WPF ComboBox Binding to ObservableCollection

眉间皱痕 提交于 2019-12-09 17:10:43
问题 I'm new to WPF And I have a question. I have the Organization module: class Organization : ObservableObject { public string OrganizationName { get; set; } } I have the ViewModel of the Organization: class OrganizationViewModel : ObservableObject { int _count = 0; public OrganizationViewModel() { Organization = new Organization {OrganizationName = "New Organization"}; } public Organization Organization { get; set; } public string OrganizationName { get { return Organization.OrganizationName; }

How to filter Observable Collection Class Collection

好久不见. 提交于 2019-12-09 15:37:36
问题 I have implemented Linq-To-Sql.. Add necessary table in it... after that linq class will automatically set property for field.. I implemented one class using ObservableCollection class.. and pass datacontextclass object in its constructor... so after getting all data how to filter it? public class BindBookIssueDetails : ObservableCollection { public BindBookIssueDetails(DataClasses1DataContext dataDC) { foreach (Resource_Allocation_View res in dataDC.Resource_Allocation_Views) { this.Add(res)