inotifypropertychanged

Should our own code subscribe to PropertyChanged?

别等时光非礼了梦想. 提交于 2019-12-08 03:10:15
问题 We have a number of data objects that realize INotifyPropertyChanged to allow for WPF Binding updates. There are also a number of places where our code subscribes to PropertyChanged because we're interested in some value updates. This results in pretty ugly code where we need to check which property actually changed (we do this using Expressions so it's always type/refactor safe). Is the preference to raise a specific event (PriceChanged etc...) for when we want to subscribe to it, or hook

WPF - Implementing System.ComponentModel.INotifyPropertyChanged for Base Class

元气小坏坏 提交于 2019-12-08 00:25:10
问题 I'd like to implent the System.ComponentModel.INotifyPropertyChanged interface for a property on a base class, but I'm not quite sure how to hook it up. Here's the signature for the property I'd like to get notifications for: public abstract bool HasChanged(); And my code in the base class for handling the change: public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(String info) { PropertyChangedEventHandler handler = PropertyChanged;

Xamarin ListView bound to ObservableCollection changing at random

故事扮演 提交于 2019-12-07 23:16:58
问题 Please consider the following issue: I have a Xamarin Forms project, using ViewModels and XAML binding. I have a particular ListView that is bound to an ObservableCollection of a particular object. The objects contain all the required information to display the following list of buttons: <ListView ItemsSource="{Binding ListViewItems}" Margin="0,20,0,0" RowHeight="130" SeparatorVisibility="None" VerticalOptions="FillAndExpand" Grid.Column="1" Grid.Row ="0" > <ListView.ItemTemplate>

Best performance for ObservableCollection.AddRange

大兔子大兔子 提交于 2019-12-07 08:37:11
问题 I'm writing an extension method for ObservableCollection and have read that the .Add function raises 3 property changed events per call, So that something like this is a bad idea: public static void AddRange<T>(this ObservableCollection<T> oc, IEnumerable<T> collection) { if (collection == null) { throw new ArgumentNullException("collection"); } foreach (var i in collection) { oc.Add(i); } } Are there any other solutions to this? 回答1: Given that Concat<T> is an extension method it is almost

WPF Binding with INotifyPropertyChanged does not update

廉价感情. 提交于 2019-12-07 01:21:22
问题 I appear to be having serious problems getting my WPF UI to update when I update when I update the property it is bound to. Here is my view model class definition: namespace WpfModel { class AppModel : INotifyPropertyChanged { private int _count = 7; public int Count { get { return _count; } set { _count = value; OnPropertyChanged("Count"); } } public void Increment() { Count++; } public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string prop) {

WPF: INotifyPropertyChanged And derived properties on different objects

浪子不回头ぞ 提交于 2019-12-06 15:54:01
问题 Recently I inherited a pretty big project developed in C# and WPF. It uses bindings along with the INotifyPropertyChanged interface to propagate changes to/from the View. A little preface: In different classes I have properties that depend on other properties in the same class (think for example the property "TaxCode" that depends on properties like "Name" and "Lastname"). With the help of some code I found here on SO (can't find again the answer though) I created the abstract class

INotifyPropertyChanged event not firing when Observable Collection changed in WPF in VB.NET

可紊 提交于 2019-12-06 15:51:53
I'm trying to use databinding in WPF with an MVVM pattern. So far, it seems that everything is plumbed up properly and I'm using the right type of classes and objects. My observable collection loads to first time correctly, but won't refresh on the datagrid when it changes. Observable Collections should automatically implement INPC and I've also provided a handler for it in my base class, so I'm confused why it is still not working and updating my UI. Here's my code below: ViewModelBase Class: #Region "INotifyPropertyChanged Members" Public Event PropertyChanged As PropertyChangedEventHandler

How do I use INotifyPropertyChanged in WinRT?

戏子无情 提交于 2019-12-06 15:34:24
问题 I'm a total newbie, just learning the basics of DataContext and the MVVM model. I've now got a grid bound to a view model object which implements INotifyPropertyChanged , however it appears that UpdateSourceTrigger (which all the WPF tutorials tell me to use) is not available for WinRT / Metro Style apps! How do I implement INotifyPropertyChanged then? I'm at the end of my tether here. I've spend nearly the whole day on the most basic of app examples, simply trying to get a grid to update

Show Computed Property in Entity Framework and WPF UI

北战南征 提交于 2019-12-06 12:45:14
I have a Download Entity in my EF Data Model. Two of its properties, Size and BytesDownloaded, compute to give me the Progress property I've created in the partial class: partial class Download { public int Progress { get { if (!Size.HasValue || Size.Value == 0) return 0; return Convert.ToInt32(Math.Floor(100.0 * ((double)BytesDownloaded / (double)Size))); } } } In my WPF UI I have: <DataGridTemplateColumn x:Name="progressColumn" Header="Progress" Width="*"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <ProgressBar Value="{Binding Path=Progress, Mode=OneWay}" Maximum="100" /> <

Observe PropertyChanged on items in an ObservableCollection using System.Reactive

只愿长相守 提交于 2019-12-06 05:26:40
I have: public class Vm { private ObservableCollection<Thing> _things; public ObservableCollection<Thing> Things { get { return _things ?? (_things = new ObservableCollection<Thing>()); } } } And public class Thing :INotifyPropertyChanged { private string _value; public string Value { get { return _value; } set { if (value == _value) return; _value = value; OnPropertyChanged(); } } public event PropertyChangedEventHandler PropertyChanged; [NotifyPropertyChangedInvocator] protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChangedEventHandler