-
Notifications
You must be signed in to change notification settings - Fork 3
AutoCollection
- Derived from the
CollectionControl
. - Compatible with the autolayout conception via the
UIDescriptor
. - Implements the
System.Collections.IList
interface. - Implements the
WpfHandler.UI.AutoLayout.IGUIField
interface. - Handle the
IGUIField.ValueChanged
event to respond when the user changes aAutoCollection
. - In case if the
source
isIsFixedSize
ofIsReadOnly
then blocks the add and remove buttons, and disabling reorder option. - In case if the
source
has generic types, then the first one will be used as the default type for the list items duringOnAdd
callback handling. You can override that handler by subscribing the custom handler on theAutoCollection.OnAddEvent
.
In that example we'll define the static array resource and apply it as the source of the AutoCollection
.
Definig the array like a static resource.
<Window.Resources>
<x:Array Type="{x:Type sys:String}" x:Key="stringStaticArray">
<sys:String>A</sys:String>
<sys:String>B</sys:String>
<sys:String>C</sys:String>
</x:Array>
</Window.Resources>
Applying the stringStaticArray
as a value of the AutoCollection
control.
<wpfh:AutoCollection Value="{StaticResource ResourceKey=stringStaticArray}"/>
In that example we'll define the source of the AutoCollection
defined at the XAML from the code behind.
<wpfh:AutoCollection x:Name="collection" MaxHeight="200"/>
// Binding the int collection to the second AutoCollection control.
var intCollection = new List<int>(new int[] { 0, 20, 40, 60 });
collection.Value = intCollection;
In that example we'll consider the few case of the defining AutoCollection
from the class derived from UIDescriptor
.
Look also: Autolayout getting started
// Declaring the int array member.
// The collection binded to that source will not has control buttons.
// Also you would unable to reorder the elements.
// That's caused by the `IsFixedSize` state of the `Array`.
// By default instiniated elements will be represented
// by `FlatTextBox` control with the `ValueMode` equal to `Mode.Int`.
public int[] intArray = new int[]{0, 1, 2, 3, 4, 5};
// The `List` member fully compatible with
// all features of the `AutoCollection` control.
// `Add Event` not overridden so the collection will manage
// the string type (the first generic type)
// like the default for all new items added via UI.
public List<string> stringList = new List<string>();
// The empty costructor of the descriptor.
public ACExample()
{
// Adding elemetns to the string list.
stringList.Add("string 1");
stringList.Add("string 2");
stringList.Add("string 3");
}
Now let's add a collection with a flexible elements type.
Also we'll costomise the element properties and override the default OnAddClick
handler by new one that add the new int field.
flexibleCollection
has defined theobject
generic type. AutoCollection unable to instantiate theIGUIField
for theobject
member by default. That could be fixed by registing theobject
competibleIGUIField
into the autolayout handler. More about...
// Enum that will be used like a source for
// the toggle control.
public enum Mode
{
Option1,
Option2,
Option3
}
// Redefining some collection options.
[AutoCollectionProperties(
// Disabling splitters.
SplitersDraw = false,
// Disabling items drag.
DragAllowed = false,
// Disabling remove button.
RemoveButtonVisibile = false)]
public List<object> flexibleCollection = new List<object>();
public ACExample()
{
...
// Adding the enum field.
flexibleCollection.Add(Mode.Option1);
// Adding the string field.
flexibleCollection.Add("example text field");
// Adding the double field.
flexibleCollection.Add(2.0d);
// Subsribing to the descriptor loading event.
Loaded += ACExample_Loaded;
}
// Occurs when descripto UI instiniated and ready to use.
private void ACExample_Loaded(UIDescriptor obj)
{
// Looking for the UI field binded to the `flexibleCollection` member.
var field = GetFieldByMember("flexibleCollection");
var collection = field as AutoCollection;
// Subscribing on the `Add item` event.
collection.OnAddClick += delegate (object sender)
{
// Adding the int field.
collection.Add(0);
};
}
#Links
- Donate: Why support the initiative? | Patreon
- Contacts: LinkedIn
- See also: Doloro Networking Framework | Uniform Data Operator | Datum Point