.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

SelectedItems Using PagedCollectionView Using PropertyChanged

Posted By: Asim Sajjad     Posted Date: September 16, 2011    Points: 2   Category :Silverlight
In my post "Get SelectedItems From DataGrid Using MVVM In Silverlight " I have used command and triggers to get the selected items of the datagrid control. Here we will get the selected item of the data grid control without using the command and trigger. Here we will use the PagedCollectionView to get the selected items. So that we can remove the use of the command and the triggers which we have used in the "Get SelectedItems From DataGrid Using MVVM In Silverlight" post and we will take advantage of INotifyPropertyChanged interface.

View Complete Post

More Related Resource Links

PropertyChangedEventHandler handler = this.PropertyChanged;

Ah yes the INotifyProperty interface defines the event in title of this post.   A well known pattern often is seen on the internet in using this Interface.  Josh Smith includes this pattern in his ViewModelAbstractBase class as shown here: Implementation of INotifyProperyChanged in ViewModel Abstract Base Class     #region INotifyPropertyChanged Members         /// <summary>         /// Raised when a property on this object has a new value.         /// </summary>         public event PropertyChangedEventHandler PropertyChanged;         /// <summary>         /// Raises this object's PropertyChanged event.         /// </summary>         /// <param name="propertyName">The property that has a new value.</param>         protected virtual void

XAML - ValueConverter Parameters and PropertyChanged callback

Hi I am trying to use a IValueConverter on the flowdocument of a richtextbox. However, ideally I'd like to be able to inject some dependencies into the converter on construction or perhaps with a setter of some sort. Previously I've been using an IoC to construct a formatter-type object and can obviously specify the constructor dependency quite easily. However, I was hoping to use XAML and the IValueConverter as much as possible, but specifying the converter in the Grid.Resources requires a parameterless constructor. Are there other ways in which I can do this or do I need to think about the problem differently. In addition, because you cannot bind to a RichTextBox, I have introduced an AttachedProperty. Here's some code     Public Shared ReadOnly DocumentProperty As DependencyProperty = DependencyProperty.RegisterAttached("Document", GetType(FlowDocument), GetType(RichTextBoxExtensions), RichTextBoxFrameworkPropertyMetaData) Private Shared Function RichTextBoxFrameworkPropertyMetaData() As FrameworkPropertyMetadata Dim metaData = New FrameworkPropertyMetadata metaData.BindsTwoWayByDefault = True metaData.AffectsRender = True metaData.PropertyChangedCallback = New PropertyChangedCallback(Sub(obj, e) If _recursionProtection.Contains(Thread.CurrentThread) Then Return Dim rtb = CType

PropertyOf and INotifyPropertyChanged.PropertyChanged without strings

When coding applications using design patterns such as MVP (Model-View-Presenter) or MVVM (Model-View-ViewModel), you'll find yourself using data binding and the INotifyPropertyChanged interface all over the place. This means referencing properties quite a lot. For example, when you want to notify that the value of a property has changed, you can write NotifyPropertyChange("SomeProperty") where NotifyPropertyChange is a method that invokes the INotifyPropertyChanged.PropertyChanged event. The major inconvenience of using a string to reference a property name, as in NotifyPropertyChange("SomeProperty"), is that it's a very brittle approach. If the name of the property changes or the property is removed during some refactoring operation on the source code, then it's easy to forget to update all the "string references". Luckily, solutions exist to avoid this kind of issues. infoof => PropertyOf, FieldOf, MethodOf, ConstructorOf We don't have propertyof or infoof operators in C# (see 1, 2, 3 or 4), but we can use things such as PropertyOf thanks to expression trees. You can learn more about such an approach on the C# FAQ blog and Patrick Smacchia's blog. Here is the source code, derived from the above articles, that I use in a utility class: Snippet public static MethodInfo MethodOf<T>(Expression<Func<T>> expression){  var&

ViewModel PropertyChanged

Hi all In my Viewmodel i have this property: BusinessAnagrafica _businessAnagrafica; public BusinessAnagrafica BusinessAnagrafica {     get     {         return _businessAnagrafica;     }     set     {         if (value != _businessAnagrafica)         {             if (_businessAnagrafica != null) _businessAnagrafica.AnagraficaModel.Recapito.PropertyChanged -= OnAnagraficaChanged;             _businessAnagrafica = value;             if (_businessAnagrafica != null)             {                 if (_businessAnagrafica != null) _businessAnagrafica.AnagraficaModel.Recapito.PropertyChanged += OnAnagraficaChanged;             }         }     } } in my View i have a textbox with this binding: Text="{Binding BusinessAnagrafica.AnagraficaModel.Recapito.TextRecapito, ValidatesOnDataErrors=True, UpdateSource

Raising PropertyChanged on a background thread.

What's the official word from Microsoft on raising the PropertyChanged event on a background thread for a property that's bound to a WPF gui? A couple blogs/sites say that the event is automatically dispatched to the UI thread. I am able to verify this in my own my own tests. I can bind to a property on a view model and then set the property on a background thread without issues. I am able to verify that the property setter is called on a background thread; yet, the UI updates without issues. An example property:   private Brush _background; public Brush Background { get { if (this ._background == null ) { this ._background = Brushes.Blue; } return this ._background; } set { if (this ._background != null ) { Debug.WriteLine(Application.Current.Dispatcher.CheckAccess() ? "On UI Thread" : "On Background Thread" ); this ._background = value; this .OnPropertyChanged("Background" ); } } } If I set this property on a background thread, all backgrounds on controls bound to this property will change without problems. Any official word on this behavior?  

WPF Datagrid multiple selecteditems in MVVM



I have a Datagrid (VS 2010 .NET 4) and using MVVm pattern in my application. I need to build a context menu that allows to perform an operation on one or more selected rows of the underling datagrid. I don't understand how to send the list of selected items to the view model from the view. Can anybody help me out.



How to force update all child controls values (like PropertyChanged but for entire child descendant



We need after event user fired (change at dataContext object) uptade all values binded to datacontext on controls descendant of grid control

¿Its is possible?


Julio Trujillo Leon. Microsoft Certified Professional Developer. .NET Developer and TFS admin. . Please, if my contribution is useful for you press on "useful button" Por favor, si les ha sido útil pulsen en "el mensaje ha sido útil" https://www.mcpvirtualbusinesscard.com/VBCServer/JulioTrujilloLeon/interactivecard

PropertyChanged on unselected item


I have master-detail relationship. Master is a table and depending on the selected row I fill a combobox (detail). Because I need to know what's selected in the combobox I handle the PropertyChanged-event. So far so good.

The problem starts if I select another row in my master table. In this case a PropertyChanged-event on combobox of the "UNSELECTED" row gets fired. If I evaluate the value I get the new current value of the combobox of the selected master-row... I would like to persist the current combox-values in the PropertyChanged-Handler. But in this case I can't do that because I would store the combobox-value of the current row as the value for the previous selected row...

What have I done wrong?? Do I miss the point?

PropertyChanged not work


Here is the code :

        public FBooks SelectedBook
            get { return _selectedBook; }
                _selectedBook = value;

                //The PropertyChanged is always null.

               //But it can work when set the value from UI.
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("SelectedBook"));                  

TextBlock Text not refreshed after raising PropertyChanged - object instance the same, ToString() re



I am working with an object that handles localized strings.  The object type (LocalizedString) provides the correct localized string in its ToString() method.

I have a view model that exposes a property of type LocalizedString.  When my current thread and ui culture is changed, I raise the property changed event for this property, however the strings in the UI do not get updated.

I narrowed it down some to discover that it stops working after the value has been read from the property once.  If instead of just raising property changed when the culture changes I do this:


LocalizedString temp = MyProperty;
MyProperty = null;
MyProperty = temp; // <-- property changed gets raised in the setter 


It seems to work.  The only difference is that the LocalizedString object instance changed.

Basically I believe what happens is this:  The dependency property (TextBlock.Text in this case) gets notified that the bound value has changed.  It goes and retrieves the property value (LocalizedString object), does a comparison and sees that the previous value and the new value are the same object instance, and stops - does not refresh the

Get SelectedItems From DataGrid Using MVVM In Silverlight

In this post what I want to learn and to share something like how to get the selected items from the data grid control of the Silver light using MVVM. You can see the main output of the example code in the Image 1, here you can see that I have a data grid control and three button with label Add, edit and delete records. Let me explain you what is happening in the example code, user is allowed to select multiple record from the grid and the selected records Ids are displayed in the "Selected Ids" area. If user select only one record then add and edit buttons are enabled and if records are more then one then add and edit buttons are disabled. Similarly If number of selected item count is shown in the delete button text.

Using PagedCollectionView Filter Using MVVM

When using data grid control there may be large amount of records in the data grid and to find out record which user is search is very difficult as he/she has to view every record to find out the desired record. So it is nice idea to have filter on the data grid records so the user can filter data grid records and find what he/she is looking in the data grid records

Using PagedCollectionView To Group DataGrid Records Using MVVM

When using data grid control sometime we provide grouping of data so that user can see records in groups but the groups are predefine and If you don't want to see the group which we the developer or the client provide then he/she can't change. So here we can use approach to provide the grouping of data to the end user if he/she want to see the data grid records in groups then he/she can arrange records in groups but if he/she don't want to see the he/she can remove the grouping of records.

Remove Datagrid Default Row Selection Using PagedCollectionView

If you have used Datagrid control then you know by default first Row of the Datagrid control is selected and if you have used the RowDetailTemplate then the RowDetailTemplate of the selected row (which is in this case is the first row) is expanded.So here we will remove the default row selection of the data grid control by using the PagedCollectionView.

Display Total Records After Applying PagedCollectionView Filter

When we used the data grid control to show total number of records which are displayed in the data grid. But if you use or apply Filter to filter the records based on the user input then the number of records displayed in the data grid are changed which need to update as use changed the filter criteria.

Best Way to Use PagedCollectionView With Datagrid Control

I have used Paged Collection view whenever I need to create application which has data grid control to display the item in tabular format. I used to new collection every time I get data and then create new Paged collection view. In this post I will show you how to use one collection and update it. Which I think is best practice to use the Paged collection view with data grid control.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend