From 92c16ced826a835f3a29239cee857cf76abd57eb Mon Sep 17 00:00:00 2001 From: "sebastian.kurfer" Date: Tue, 26 Jul 2016 14:30:54 +0200 Subject: [PATCH] Refactored Displayable to inherit DependencyObject to be able to register DisplayName and Source of Link and LinkGroup as DependencyProperties to be able to bind them for i18n purposes --- .../Shared/Presentation/Displayable.cs | 25 +++++++--------- .../Shared/Presentation/Link.cs | 26 +++++++--------- .../Presentation/NotifyPropertyChanged.cs | 30 +++++++++---------- 3 files changed, 35 insertions(+), 46 deletions(-) diff --git a/1.0/FirstFloor.ModernUI/Shared/Presentation/Displayable.cs b/1.0/FirstFloor.ModernUI/Shared/Presentation/Displayable.cs index 2ee0377a..c73f818c 100644 --- a/1.0/FirstFloor.ModernUI/Shared/Presentation/Displayable.cs +++ b/1.0/FirstFloor.ModernUI/Shared/Presentation/Displayable.cs @@ -1,33 +1,30 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Windows; namespace FirstFloor.ModernUI.Presentation { /// - /// Provides a base implementation for objects that are displayed in the UI. + /// Provides a base implementation for objects that are displayed in the UI. /// public abstract class Displayable : NotifyPropertyChanged { - private string displayName; /// - /// Gets or sets the display name. + /// DependencyProperty for DisplayName to be able to bind the property + /// + public static readonly DependencyProperty DisplayNameProperty = DependencyProperty.Register("DisplayName", typeof(string), typeof(Displayable), new PropertyMetadata("")); + + /// + /// Gets or sets the display name. /// /// The display name. public string DisplayName { - get { return this.displayName; } + get { return (string)GetValue(DisplayNameProperty); } set { - if (this.displayName != value) { - this.displayName = value; - OnPropertyChanged("DisplayName"); - } + SetValue(DisplayNameProperty, value); } } } -} +} \ No newline at end of file diff --git a/1.0/FirstFloor.ModernUI/Shared/Presentation/Link.cs b/1.0/FirstFloor.ModernUI/Shared/Presentation/Link.cs index e59497d7..1638175b 100644 --- a/1.0/FirstFloor.ModernUI/Shared/Presentation/Link.cs +++ b/1.0/FirstFloor.ModernUI/Shared/Presentation/Link.cs @@ -1,33 +1,27 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Windows; namespace FirstFloor.ModernUI.Presentation { /// - /// Represents a displayable link. + /// Represents a displayable link. /// public class Link : Displayable { - private Uri source; + /// + /// DependencyProperty for Source to be able to bind the value + /// + public static readonly DependencyProperty SourceProperty = DependencyProperty.Register("Source", typeof(Uri), typeof(Link), new PropertyMetadata(null)); /// - /// Gets or sets the source uri. + /// Gets or sets the source uri. /// /// The source. public Uri Source { - get { return this.source; } - set - { - if (this.source != value) { - this.source = value; - OnPropertyChanged("Source"); - } - } + get { return (Uri) GetValue(SourceProperty); } + set { SetValue(SourceProperty, value); } } } -} +} \ No newline at end of file diff --git a/1.0/FirstFloor.ModernUI/Shared/Presentation/NotifyPropertyChanged.cs b/1.0/FirstFloor.ModernUI/Shared/Presentation/NotifyPropertyChanged.cs index 267fb032..d2af1e14 100644 --- a/1.0/FirstFloor.ModernUI/Shared/Presentation/NotifyPropertyChanged.cs +++ b/1.0/FirstFloor.ModernUI/Shared/Presentation/NotifyPropertyChanged.cs @@ -1,48 +1,46 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; +using System.ComponentModel; using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; +using System.Windows; namespace FirstFloor.ModernUI.Presentation { /// - /// The base implementation of the INotifyPropertyChanged contract. + /// The base implementation of the INotifyPropertyChanged contract. /// public abstract class NotifyPropertyChanged - : INotifyPropertyChanged + : DependencyObject, INotifyPropertyChanged { /// - /// Occurs when a property value changes. + /// Occurs when a property value changes. /// public event PropertyChangedEventHandler PropertyChanged; /// - /// Raises the PropertyChanged event. + /// Raises the PropertyChanged event. /// /// Name of the property. protected virtual void OnPropertyChanged(string propertyName) { - var handler = this.PropertyChanged; - if (handler != null) { + var handler = PropertyChanged; + if (handler != null) + { handler(this, new PropertyChangedEventArgs(propertyName)); } } #if !NET4 /// - /// Updates specified value, and raises the event when the value has changed. + /// Updates specified value, and raises the event when the value has changed. /// /// The type of the value. /// The current stored value /// The new value /// The optional property name, automatically set to caller member name when not set. /// Indicates whether the value has changed. - protected bool Set(ref T storage, T value, [CallerMemberName]string propertyName = null) + protected bool Set(ref T storage, T value, [CallerMemberName] string propertyName = null) { - if (!object.Equals(storage, value)) { + if (!Equals(storage, value)) + { storage = value; OnPropertyChanged(propertyName); return true; @@ -51,4 +49,4 @@ protected bool Set(ref T storage, T value, [CallerMemberName]string propertyN } #endif } -} +} \ No newline at end of file