Last active
December 13, 2015 20:38
-
-
Save nesteruk/4970909 to your computer and use it in GitHub Desktop.
Bindable CheckBoxElement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApplication1 | |
{ | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Runtime.CompilerServices; | |
using Annotations; | |
public class CheckBoxElement : INotifyPropertyChanged, IEquatable<CheckBoxElement> | |
{ | |
public bool Equals(CheckBoxElement other) | |
{ | |
if (ReferenceEquals(null, other)) return false; | |
if (ReferenceEquals(this, other)) return true; | |
return string.Equals(text, other.text); | |
} | |
public override bool Equals(object obj) | |
{ | |
if (ReferenceEquals(null, obj)) return false; | |
if (ReferenceEquals(this, obj)) return true; | |
if (obj.GetType() != this.GetType()) return false; | |
return Equals((CheckBoxElement) obj); | |
} | |
public override int GetHashCode() | |
{ | |
return (text != null ? text.GetHashCode() : 0); | |
} | |
public static bool operator ==(CheckBoxElement left, CheckBoxElement right) | |
{ | |
return Equals(left, right); | |
} | |
public static bool operator !=(CheckBoxElement left, CheckBoxElement right) | |
{ | |
return !Equals(left, right); | |
} | |
public CheckBoxElement(string text, bool @checked) | |
{ | |
this.text = text; | |
this.@checked = @checked; | |
} | |
private string text; | |
private bool @checked; | |
[Bindable(true)] | |
public string Text | |
{ | |
get { return text; } | |
set | |
{ | |
if (value == text) return; | |
text = value; | |
OnPropertyChanged(); | |
} | |
} | |
public bool Checked | |
{ | |
get { return @checked; } | |
set | |
{ | |
if (value.Equals(@checked)) return; | |
@checked = value; | |
OnPropertyChanged(); | |
} | |
} | |
public event PropertyChangedEventHandler PropertyChanged; | |
[NotifyPropertyChangedInvocator] | |
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) | |
{ | |
PropertyChangedEventHandler handler = PropertyChanged; | |
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment