Note that there are some explanatory texts on larger screens.

plurals
  1. POthis.VerifyPropertyName(propertyName); in OnPropertyChanged() always returns null
    text
    copied!<p>I have a xaml code as follows: On MouseLeftButtonDown i redirect it to viewModel where the color GenerateGlowEffect must change. This is not reflected. It always returns null for this.PropertyChanged XAML:</p> <pre><code>&lt;UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" xmlns:telerikDocking="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Docking" xmlns:Telerik_Windows_Controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" xmlns:System="clr-namespace:System;assembly=mscorlib" x:Class="TabItemContents.MapDetail" mc:Ignorable="d" Width="Auto" Height="430.333"&gt; &lt;Grid x:Name="LayoutRoot" Background="{StaticResource TabControlActiveAreaColor}" Height="430.333" VerticalAlignment="Top" HorizontalAlignment="Left"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="192.833"/&gt; &lt;RowDefinition/&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Rectangle IsHitTestVisible="True" x:Name="Rectangle_Generate" Margin="25.334,70.167,0,65.333" Cursor="{DynamicResource HandCursor}" RadiusX="10" RadiusY="10" HorizontalAlignment="Left" Width="88.5" StrokeThickness="1.5" d:LayoutOverrides="HorizontalAlignment" MouseLeftButtonDown="Rectangle_Generate_MouseLeftButtonDown" &gt; &lt;Rectangle.Fill&gt; &lt;SolidColorBrush Color="{DynamicResource RectangleColor}"/&gt; &lt;/Rectangle.Fill&gt; &lt;Rectangle.Effect &gt; &lt;DropShadowEffect RenderingBias="Quality" BlurRadius="{DynamicResource BlurRadius}" ShadowDepth="0" Color="{Binding GenerateGlowEffect}" /&gt; &lt;/Rectangle.Effect&gt; &lt;/Rectangle&gt; &lt;/Grid&gt; </code></pre> <p> CODEBEHIND:</p> <pre><code>public partial class MapDetail : UserControl { ViewModel ViewModelObject; public MapDetail() { InitializeComponent(); ViewModelObject= new ViewModelObject((IUnityContainer)Application.Current.Properties["UnityContainer"]); } private void Rectangle_Generate_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { ViewModelObject.SetColor(); } } </code></pre> <p>VIEWMODEL:</p> <pre><code>public class ViewModel : ViewModelBase { private IUnityContainer _unityContainer; private ILogger _logger; private Model model; private string _generateGlowEffect; public ViewModel(IUnityContainer unityContainer) { _unityContainer = unityContainer; try { model = new Model(unityContainer); } catch (Exception ex) { throw ex; } } public void SetColor() { GenerateGlowEffect = "White"; } public string GenerateGlowEffect { get { return _generateGlowEffect; } set { _generateGlowEffect = value; OnPropertyChanged("GenerateGlowEffect"); } } } } public string GenerateGlowEffect { get { return _generateGlowEffect; } set { _generateGlowEffect = value; OnPropertyChanged("GenerateGlowEffect"); } } </code></pre> <p>ViewModelBase:</p> <pre><code>public class ViewModelBase : INotifyPropertyChanged, IDisposable { #region Constructor protected ViewModelBase() { } #endregion // Constructor #region DisplayName /// &lt;summary&gt; /// Returns the user-friendly name of this object. /// Child classes can set this property to a new value, /// or override it to determine the value on-demand. /// &lt;/summary&gt; public virtual string DisplayName { get; protected set; } #endregion // DisplayName #region Debugging Aides /// &lt;summary&gt; /// Warns the developer if this object does not have /// a public property with the specified name. This /// method does not exist in a Release build. /// &lt;/summary&gt; [Conditional("DEBUG")] [DebuggerStepThrough] public void VerifyPropertyName(string propertyName) { // Verify that the property name matches a real, // public, instance property on this object. if (TypeDescriptor.GetProperties(this)[propertyName] == null) { string msg = "Invalid property name: " + propertyName; if (this.ThrowOnInvalidPropertyName) throw new Exception(msg); else Debug.Fail(msg); } } /// &lt;summary&gt; /// Returns whether an exception is thrown, or if a Debug.Fail() is used /// when an invalid property name is passed to the VerifyPropertyName method. /// The default value is false, but subclasses used by unit tests might /// override this property's getter to return true. /// &lt;/summary&gt; protected virtual bool ThrowOnInvalidPropertyName { get; private set; } #endregion // Debugging Aides #region INotifyPropertyChanged Members /// &lt;summary&gt; /// Raised when a property on this object has a new value. /// &lt;/summary&gt; public event PropertyChangedEventHandler PropertyChanged; /// &lt;summary&gt; /// Raises this object's PropertyChanged event. /// &lt;/summary&gt; /// &lt;param name="propertyName"&gt;The property that has a new value.&lt;/param&gt; protected virtual void OnPropertyChanged(string propertyName) { this.VerifyPropertyName(propertyName); PropertyChangedEventHandler handler = this.PropertyChanged; if (handler != null) { var e = new PropertyChangedEventArgs(propertyName); handler(this, e); } } #endregion // INotifyPropertyChanged Members #region IDisposable Members /// &lt;summary&gt; /// Invoked when this object is being removed from the application /// and will be subject to garbage collection. /// &lt;/summary&gt; public void Dispose() { this.OnDispose(); } /// &lt;summary&gt; /// Child classes can override this method to perform /// clean-up logic, such as removing event handlers. /// &lt;/summary&gt; protected virtual void OnDispose() { } #endregion // IDisposable Members } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload