Created
September 24, 2016 19:21
-
-
Save se5a/f59b63b45ee43f8506aed0bc24e315be to your computer and use it in GitHub Desktop.
Eto GenericControlStack
This file contains 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; | |
using Eto.Forms; | |
using Eto.Serialization.Xaml; | |
using System.Collections.Specialized; | |
using System.Collections; | |
namespace Pulsar4X.CrossPlatformUI.Views | |
{ | |
public class GenericStackControl : Panel | |
{ | |
protected StackLayout Stack; | |
internal Type ControlType { get; set; } = typeof(Label); | |
public GenericStackControl() | |
{ | |
XamlReader.Load(this); | |
DataContextChanged += GenericStackControl_DataContextChanged; | |
} | |
private void GenericStackControl_DataContextChanged(object sender, EventArgs e) | |
{ | |
Type dcType = DataContext.GetType(); | |
if (DataContext is ICollection) | |
{ | |
var collection = (ICollection)DataContext; | |
Stack.Items.Clear(); | |
foreach (var item in collection) | |
{ | |
Control ctrl = (Control)Activator.CreateInstance(ControlType); | |
ctrl.DataContext = item; | |
Stack.Items.Add(ctrl); | |
} | |
if (DataContext is INotifyCollectionChanged) | |
{ | |
var objcollection = (INotifyCollectionChanged)DataContext; | |
objcollection.CollectionChanged += Collection_CollectionChanged; | |
} | |
} | |
} | |
private void Collection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment