inotifypropertychanged

When to use a WPF Dependency Property versus INotifyPropertyChanged

倖福魔咒の 提交于 2019-12-28 11:44:11
问题 Do folks have any guidance on when a simple .NET property that fires INotifyPropertyChanged.PropertyChanged is sufficient in a view model? Then when do you want to move up to a full blown dependency property? Or are the DPs intended primarily for views? 回答1: There are a few approaches: 1. The dependency property While you using the dependency property it makes the most sense in elements-classes that have a visual appearance ( UIElement s). Pros: WPF do the logic stuff for you Some mechanism

WPF: Bind property to TextBlock not working

只谈情不闲聊 提交于 2019-12-25 17:17:28
问题 I have below xaml file (this a piece): <Grid Opacity="1" Margin="5"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <Label Grid.Row="0" Grid.Column="0" Content="ID"/> <Label Grid.Row="0" Grid.Column="1" Content="Name"/> <Label Grid.Row="0" Grid.Column="2" Content="Description"/>

ObservableCollection with INotifyPropertyChanged into DatagridComboboxColumn Binding

淺唱寂寞╮ 提交于 2019-12-25 07:19:03
问题 My little project looks now quite different. Now I have ObservableCollection PackagesList with data which I want to bind with whole DataGrid (via Binding Path) and ObservableCollection DestinationItememsSource where I store cases for DataGridComboboxColumn (as ItemsSourceBinding). SelectedItem property in DatagridComboboxColumn is one value from PackageInfo (and it is one of DestinationNames cases ofc). Binding on DatagridTextBoxColumns is ok. XAML: <Window x:Class="test01.MainWindow" xmlns=

C# custom control - Redraw after changing a member object's properties

巧了我就是萌 提交于 2019-12-25 05:08:34
问题 C# - .Net4.0, Visual Studio 2010 For certain reasons I'm using a separate class to store some of my custom control's properties (properties to do with drawing a grid). This is causing some problems, since I'd like to be able to call "Invalidate()" any time these values are edited (either via the properties window, or during run-time), to automatically redraw the control. The best solution I could think of was to implement INotifyPropertyChanged within my "GridProperties" class, fire off a

How to decompose expression to satisfy generic property change method?

天涯浪子 提交于 2019-12-25 03:41:14
问题 I have a base EF entity class which implements INotifyPropertyChanged . The base property, Id is my example: /// <summary> /// Entity Id /// </summary> public int Id { get { return id; } set { SetValue<int>(() => (Id != value), (v) => id = v); } // < can this be simplified into a single call? } ...where SetValue is defined: protected void SetValue<TValue>(Expression<Func<bool>> evalExpr, Action<TValue> set) { // Compile() returns a Func<bool> var doSetValue = evalExpr.Compile(); if

Using INotifyPropertyChanged to refresh a databound datagrid?

我们两清 提交于 2019-12-25 02:24:09
问题 I have created a databound datagrid in WPF: 'ActionResults', when I run the application it shows the contents of the database table. The I.T dept. are going to manually update the 'ActionResult' table in SQL server management studio. If any changes are made to the table, they will display in the datagrid only after I restart the application. I would like to add an 'Update' button which will re-fresh the datagrid, displaying any changes made to the table. I was previously trying to do a hack

It is necessary to use INotifyPropertyChanged on properties of type ICommand in WPF MVVM?

允我心安 提交于 2019-12-25 02:19:33
问题 Is there a difference between this two variants (performance, memory leaks or guidelines)? With NPC: private ICommand mGoBackCommand; public ICommand GoBackCommand { get { return mGoBackCommand; } set { if (mGoBackCommand != value) { mGoBackCommand = value; RaisePropertyChanged("GoBackCommand"); } } } Auto property: public ICommand GoBackCommand {get; set;} UPD: Final question is: Can I use auto properties in VievModel if they are simple commands which will be assigned once in constructor, or

How to implement a property changed notification without making an explicit call?

独自空忆成欢 提交于 2019-12-24 13:56:56
问题 In WPF there is the concept of two-way data binding, where when an object property value is updated in the db, it the framework also updates the view when the INotifyPropertyChanged interface is implemented. I'm looking for something like this functionality in C# but not using WPF. The scenario is that when an object property is updated, a series of notifications are sent to the other consumers of this object, notifying them of the property change. So the flow is: Update the database Notify

INotifyPropertyChanged not working with traditonal binding but works with compiled binding

此生再无相见时 提交于 2019-12-24 12:51:38
问题 I don't if I am doing something wrong or if there is something I am missing but the INotifyPropertyChanged works when I do it with compile time binding and doesn't work when I do it with traditional binding. public class Students : INotifyPropertyChanged { private string name; private string surname; public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged([CallerMemberName] string propertyName = "") { if (PropertyChanged != null) { PropertyChanged(this,

Notification of DataGrid when Collection inside Collection changes

。_饼干妹妹 提交于 2019-12-24 08:36:09
问题 Since hours I am working on a very hard problem: How is a DataGrid that is bound to an ObservableCollection correctly updated when another ObservableCollection that is inside the ObservableCollection the DataGrid is bound to changes ? So far the DataGrid onnly refreshes when i click on the corresponding cell. I have prepared a complete source code example to illustrate the following (very simple) situation: There is a ViewModel that holds a List. This List is an ObservableCollection and hold