Skip to content

Instantly share code, notes, and snippets.

@nesteruk
Last active December 13, 2015 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nesteruk/4970909 to your computer and use it in GitHub Desktop.
Save nesteruk/4970909 to your computer and use it in GitHub Desktop.
Bindable CheckBoxElement
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