Skip to content
Browse files

Add notification support so changes are detected

  • Loading branch information...
1 parent 7661930 commit 2b08db590629e6587123411e141cbf342043757d @carlokok committed Apr 6, 2012
View
3 Source/Eto.Platform.Wpf/Forms/Controls/TreeViewHandler.cs
@@ -27,8 +27,7 @@ public TreeViewHandler ()
Control.ItemTemplate = template;
var style = new sw.Style (typeof (swc.TreeViewItem));
- style.Setters.Add (new sw.Setter (swc.TreeViewItem.IsExpandedProperty, new swd.Binding { Converter = new WpfTreeItemHelper.IsExpandedConverter (), Mode = swd.BindingMode.OneWay }));
- style.Setters.Add(new sw.Setter(swc.TreeViewItem.IsExpandedProperty, new swd.Binding { Converter = new WpfTreeItemHelper.IsExpandedConverter(), Mode = swd.BindingMode.OneWay }));
+ style.Setters.Add (new sw.Setter (swc.TreeViewItem.IsExpandedProperty, new swd.Binding { Path = new sw.PropertyPath("Expanded"), Mode = swd.BindingMode.TwoWay }));
Control.ItemContainerStyle = style;
Control.SelectedItemChanged += delegate {
View
24 Source/Eto.Platform.Wpf/Forms/Controls/WpfListItemHelper.cs
@@ -21,30 +21,14 @@ public static sw.FrameworkElementFactory ItemTemplate ()
return factory;
}
- class TextConverter : swd.IValueConverter
- {
- public object Convert (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- var item = value as IListItem;
- return (item != null) ? item.Text : null;
- }
-
- public object ConvertBack (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- throw new NotImplementedException ();
- }
- }
-
class ColorConverter : swd.IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
- var item = value as ITreeItem;
-
sw.Media.Brush lCol = sw.SystemColors.WindowTextBrush;
- if (item != null)
+ if (value != null)
{
- var col = item.TextColor;
+ var col = (Eto.Drawing.Color)value;
if (col != Eto.Drawing.Color.Transparent)
lCol = new sw.Media.SolidColorBrush(Generator.Convert(col));
}
@@ -60,8 +44,8 @@ public object ConvertBack(object value, Type targetType, object parameter, Syste
public static sw.FrameworkElementFactory TextBlock ()
{
var factory = new sw.FrameworkElementFactory (typeof (swc.TextBlock));
- factory.SetBinding (swc.TextBlock.TextProperty, new sw.Data.Binding { Converter = new TextConverter () });
- factory.SetBinding (swc.TextBlock.ForegroundProperty, new sw.Data.Binding { Converter = new ColorConverter () });
+ factory.SetBinding (swc.TextBlock.TextProperty, new sw.Data.Binding { Path = new sw.PropertyPath("Text"), Mode = swd.BindingMode.TwoWay });
+ factory.SetBinding(swc.TextBlock.ForegroundProperty, new sw.Data.Binding { Path = new sw.PropertyPath("TextColor"), Mode = swd.BindingMode.OneWay, Converter = new ColorConverter() });
return factory;
}
View
14 Source/Eto.Platform.Wpf/Forms/Controls/WpfTreeItemHelper.cs
@@ -31,18 +31,6 @@ public object ConvertBack (object value, Type targetType, object parameter, Syst
}
}
- public class IsExpandedConverter : swd.IValueConverter
- {
- public object Convert (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- var item = value as ITreeItem;
- return item.Expanded;
- }
-
- public object ConvertBack (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- return value;
- }
- }
+
}
}
View
47 Source/Eto/Forms/ListItem.cs
@@ -1,7 +1,8 @@
using System;
using Eto.Drawing;
#if DESKTOP
-using System.Windows.Markup;
+using System.Windows.Markup;
+using System.ComponentModel;
#endif
namespace Eto.Forms
@@ -16,21 +17,47 @@ public interface IListItem
#if DESKTOP
[ContentProperty("Text")]
#endif
- public class ListItem : IListItem
+ public class ListItem : IListItem, INotifyPropertyChanged
{
- string key;
-
- public string Text { get; set; }
+ string key, text;
+
+ public string Text
+ {
+ get { return text; }
+ set
+ {
+ text = value;
+ OnPropertyChanged("Text");
+ if (key == null)
+ OnPropertyChanged("Key");
+ }
+ }
public string Key {
- get { return key ?? Text; }
- set { key = value; }
- }
+ get { return key ?? Text; }
+ set { key = value; OnPropertyChanged("Key"); }
+ }
+
+ public event PropertyChangedEventHandler PropertyChanged;
+ public void OnPropertyChanged(string Name)
+ {
+ if (PropertyChanged != null)
+ PropertyChanged(this, new PropertyChangedEventArgs(Name));
+ }
}
public class ImageListItem : ListItem, IImageListItem
- {
- public Image Image { get; set; }
+ {
+ Image image;
+ public Image Image
+ {
+ get { return image; }
+ set
+ {
+ image = value;
+ OnPropertyChanged("Image");
+ }
+ }
}
#if DESKTOP
View
28 Source/Eto/Forms/TreeItem.cs
@@ -52,9 +52,31 @@ public TreeItemCollection Children
public virtual bool Expandable { get { return this.Count > 0; } }
- public virtual bool Expanded { get; set; }
-
- public virtual Color TextColor { get; set; }
+ private bool expanded;
+ public virtual bool Expanded
+ {
+ get { return expanded; }
+ set
+ {
+ expanded = value;
+ OnPropertyChanged("Expanded");
+ }
+ }
+
+ private Color textcolor;
+
+ public virtual Color TextColor
+ {
+ get
+ {
+ return textcolor;
+ }
+ set
+ {
+ textcolor = value;
+ OnPropertyChanged("TextColor");
+ }
+ }
public virtual ITreeItem this[int index]
{

0 comments on commit 2b08db5

Please sign in to comment.
Something went wrong with that request. Please try again.