Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6633563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:49:40+00:00 2026-05-25T22:49:40+00:00

I’m rather new to Silverlight and have a question about the notifying-mechanism. My solution

  • 0

I’m rather new to Silverlight and have a question about the notifying-mechanism. My solution is an MVVM-application stacked like this:

VIEW Contains a RadGridView bound to a collection in the viewmodel, the data is an entitycollection. The GridView’s SelectedItem is bound to corresponding property in the viewmodel.

VIEWMODEL
Holds the properties below that the GridView is bound to and implements INotifyPropertyChanged.
•SelectList – an entitycollection that inherits ObservableCollection. When SelectList is set, it runs a notify-call.
•SelectedItem – an entity that also implements INotifyPropertyChanged for its own properties. When SelectedItem is set, it runs a notify-call.

My question is, who should make the notify-call so that the GridView knows value has changed? Occasionally, a property in the entity is set programmatically directly in the viewmodel. As for now, nothing is happening in the GUI although the properties gets the new values correctly.

Regards, Clas

— UPDATE WITH CODE ————————-

VIEW

<UserControl 
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    x:Class="X.Y.Z.MonthReport.MonthReportView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot">
        <telerik:RadGridView x:Name="MonthReportGrid"
                             Grid.Row="1"
                             ItemsSource="{Binding SelectList}"
                             SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
                             AutoGenerateColumns="False">
            <telerik:RadGridView.Columns>
                <!-- The other columns have been cut out of this example -->
                <telerik:GridViewDataColumn DataMemberBinding="{Binding curDate, Mode=TwoWay, TargetNullValue=''}" DataFormatString="{} {0:d}" Header="Avläst datum" UniqueName="curDate" IsVisible="True" IsReadOnly="False">
                    <telerik:GridViewDataColumn.CellEditTemplate>
                        <DataTemplate>
                            <telerik:RadDateTimePicker SelectedValue="{Binding curDate, Mode=TwoWay, TargetNullValue=''}" InputMode="DatePicker" DateTimeWatermarkContent="ÅÅÅÅ-MM-DD" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellEditTemplate>
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding curValue, Mode=TwoWay, TargetNullValue=''}" Header="Avläst värde" UniqueName="curValue" IsVisible="True" IsReadOnly="False" />
        </telerik:RadGridView>
    </Grid>
</UserControl>

VIEW .CS

using System;
using System.Collections.Generic;
using System.Windows.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Windows.Controls;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;


namespace X.Y.Z.MonthReport
{

    public partial class MonthReportView : UserControl, IMonthReportView
    {
        /// <summary>
        /// ViewModel attached to the View
        /// </summary>
        public IMonthReportViewModel Model
        {
            get {   return this.DataContext as IMonthReportViewModel; }
            set {   this.DataContext = value; }
        }

        public MonthReportView()
        {
            InitializeComponent();
            this.MonthReportGrid.CellEditEnded += new EventHandler<GridViewCellEditEndedEventArgs>(MonthReportGrid_OnCellEditEnded);
        }


        public void MonthReportGrid_OnCellEditEnded(object sender, GridViewCellEditEndedEventArgs e)
        {
            if (e.Cell.Column.UniqueName == "curValue")
            {
                // ...
                this.Model.SetAutomaticReadingDate();
            }

            if (e.Cell.Column.UniqueName == "curDate")
            {
                this.Model.UpdateAutomaticReadingDate();
            }
        }
    }
}

VIEWMODEL

using System;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Prism.Commands;


namespace X.Y.Z.MonthReport
{
    public class MonthReportViewModel : ViewModel<IMonthReportView>, IMonthReportViewModel
    {
        private readonly IEventAggregator eventAggregator;
        private readonly IMonthReportService dataService;
        private readonly IMonthReportController dataController;


        private DateTime? _newReadingDate;
        public DateTime? NewReadingDate
        {
            get { return _newReadingDate; }
            set { _newReadingDate = value; }
        }

        //Holds the selected entity
        private MonthReportEntity _selectedItem;
        public MonthReportEntity SelectedItem
        {
            get { return _selectedItem; }
            set
            {
                if (_selectedItem != value)
                {
                    _selectedItem = value;
                    //The INotifyPropertyChanged implementation inherited from ViewModel-base.
                    Notify(() => this.SelectedItem);
                }
            }
        }

        //The entitycollection
        private MonthReportEntityCollection _selectList;
        public MonthReportEntityCollection SelectList
        {
            get { return _selectList; }
            set
            {
                if (_selectList != value)
                {
                    _selectList = value;
                    //The INotifyPropertyChanged implementation inherited from ViewModel-base.
                    Notify(() => this.SelectList);
                }
            }
        }

        public MonthReportViewModel(IMonthReportView view,
            IEventAggregator eventAggregator, IMonthReportService dataService, IMonthReportController dataController)
        {
            this.InitializeCommands();
            this.eventAggregator = eventAggregator;
            this.dataController = dataController;
            this.dataService = dataService;
            this.View = view;
            this.View.Model = this;

            dataService.onGetMonthReportComplete += new EventHandler<MonthReportEventArgs>(OnGetMonthReportComplete);
            dataService.onSaveMonthReportComplete += new EventHandler<MonthReportEventArgs>(OnSaveMonthReportComplete);

            InitializeData();
        }

        public void InitializeCommands()
        {
            // ...
        }

        public void InitializeData()
        {
            GetMonthReport();
        }

        //This function is not working as I want it to.
        //The gridview doesn't notice the new value.
        //If a user edits the grid row, he should not need to
        //add the date manually, Therefor I use this code snippet.
        public void SetAutomaticReadingDate()
        {
            if ((NewReadingDate.HasValue) && (!SelectedItem.curDate.HasValue))
            {
                SelectedItem.curDate = NewReadingDate;
                //The INotifyPropertyChanged implementation inherited from ViewModel-base.
                Notify(() => this.SelectedItem.curDate);
            }
        }

        public void GetMonthReport()
        {
            dataService.GetMonthReport();
        }

        public void SaveMonthReport()
        {
            dataService.SaveMonthReport(SelectList);            
        }

        void OnGetMonthReportComplete(object sender, MonthReportEventArgs e)
        {
            // ...
        }

        void OnSaveMonthReportComplete(object sender, MonthReportEventArgs e)
        {
            // ...       
        }

        #region ICleanable
        public override void Clean()
        {
            base.Clean();
        }
        #endregion
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:49:41+00:00Added an answer on May 25, 2026 at 10:49 pm

    if you do your binding like this

    <telerik:GridViewDataColumn DataMemberBinding="{Binding curValue, Mode=TwoWay, TargetNullValue=''}" Header="Avläst värde" UniqueName="curValue" IsVisible="True" IsReadOnly="False" />
    

    you just have to look at the binding to know where you have to call PropertyChanged and your binding said:

    the class whith the property “curValue” has to implement INotifyProperyChanged to get the View informed.

      public void SetAutomaticReadingDate()
        {
            if ((NewReadingDate.HasValue) && (!SelectedItem.curDate.HasValue))
            {
                //this is enough if the class of SelectedItem implements INotifyPropertyChanged
                //and the curDate Poperty raise the event 
                SelectedItem.curDate = NewReadingDate;               
            }
        }
    

    btw BAD code style to name the Property curDate! it should be CurDate, Properties with camlCase hurts my eyes 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.