<?xml version="1.0"?>
<!--<ListBox Data="{TestList}" Focusable="true"/>-->
-<Border BorderWidth="2" Fit="true">
- <VerticalStack Fit="true" Margin="50">
- <Label Text="{../ColorList.SelectedItem}" Width="-1" Background="DarkGreen"/>
- <Label Text="{Hover}" Width="-1" Background="DarkGreen"/>
- <Button Caption="Clear" Width="150" MouseClick="OnClear"/>
+<Border Margin="50">
+ <VerticalStack >
+ <Label Text="{../ColorList.SelectedItem}" Background="DarkGreen"/>
+ <Label Text="{Hover}" Background="DarkGreen"/>
+ <Button Caption="Clear" Width="0" MouseClick="OnClear"/>
<ListBox Name="ColorList" Data="{TestList}" Background="0,5;0,5;0,5;0,5"
- HorizontalAlignment="Center" Width="-1" Height="200" Margin="5">
+ HorizontalAlignment="Center" Width="-1" Height="200" Margin="0"
+ ItemTemplate="#Tests.Interfaces.colorItem.crow"
+ Template="#Crow.Templates.ScrollingListBox.goml">
<!-- <Template>
<Border BorderWidth="1" Height="{../HeightPolicy}" Width="{../WidthPolicy}">
<HorizontalStack Margin="1" Height="{../../HeightPolicy}" Width="{../../WidthPolicy}" >
</Border>
</Template>-->
</ListBox>
- <Button Caption="Load list" Width="0" MouseClick="OnLoadList"/>
+ <Button Caption="Load list" Width="0" MouseClick="../../../OnLoadList"/>
</VerticalStack>
</Border>
\ No newline at end of file
{
base.loadTemplate (template);
_list = this.child.FindByName ("List") as Group;
+ if (_list == null)
+ throw new Exception ("ListBox Template MUST contain a Goup named 'List'.");
_gsList = _list as GenericStack;
}
NotifyValueChanged ("Data", data);
_list.ClearChildren ();
+ if (_gsList.Orientation == Orientation.Horizontal)
+ _gsList.Width = -1;
+ else
+ _gsList.Height = -1;
if (data == null)
return;
Group page = _list.Clone () as Group;
page.Name = "page" + pageNum;
+ //reset size to fit in the dir of the stacking
+ //because _list total size is forced to approx size
+ if (_gsList.Orientation == Orientation.Horizontal)
+ page.Width = -1;
+ else
+ page.Height = -1;
+
for (int i = (pageNum - 1) * itemPerPage; i < pageNum * itemPerPage; i++) {
if (i >= data.Count)
{
if (_gsList == null)
return;
+ if (data == null)
+ return;
+ if (data.Count <= itemPerPage)
+ return;
if (_gsList.Orientation == Orientation.Horizontal) {
} else {
double scroll = (double)e.NewValue;
int pageHeight = (int)Math.Ceiling((double)_gsList.getSlot().Height / (double)data.Count * (double)itemPerPage);
+ int pagePtr = (int)Math.Ceiling((scroll + (double)pageHeight / 2.0) / (double)pageHeight);
- int pagePtr = (int)Math.Ceiling(scroll / (double)pageHeight);
-
- for (int i = _gsList.Children.Count+1; i <= pagePtr+1; i++) {
+ for (int i = _gsList.Children.Count+1; i < pagePtr+1; i++) {
loadPage (i);
}
}
}
protected void _list_LayoutChanged (object sender, LayoutingEventArgs e)
{
- if (_gsList == null)
- return;
-
- GenericStack page1 = _list.FindByName ("page1") as GenericStack;
- if (page1 == null)
- return;
-
if (_gsList.Orientation == Orientation.Horizontal) {
- if (e.LayoutType != LayoutingType.Width)
- return;
- int tmpWidth = (int)Math.Ceiling ((double)page1.Slot.Width / (double)itemPerPage * (double)data.Count);
- if (_gsList.Slot.Width == tmpWidth)
- return;
- _gsList.Slot.Width = tmpWidth;
- _gsList.OnLayoutChanges (LayoutingType.Width);
- _gsList.LastSlots.Width = _gsList.Slot.Width;
- } else {
- if (e.LayoutType != LayoutingType.Height)
- return;
- int tmpHeight = (int)Math.Ceiling ((double)page1.Slot.Height / (double)itemPerPage * (double)data.Count);
- if (_gsList.Slot.Height == tmpHeight)
- return;
- _gsList.Slot.Height = tmpHeight;
- _gsList.OnLayoutChanges (LayoutingType.Height);
- _gsList.LastSlots.Height = _gsList.Slot.Height;
+ if (e.LayoutType == LayoutingType.Width)
+ _gsList.Width = approxSize;
+ } else if (e.LayoutType == LayoutingType.Height)
+ _gsList.Height = approxSize;
+ }
+ int approxSize
+ {
+ get {
+ if (data == null)
+ return -1;
+ GenericStack page1 = _list.FindByName ("page1") as GenericStack;
+ if (page1 == null)
+ return - 1;
+
+ return page1.Orientation == Orientation.Horizontal ?
+ data.Count < itemPerPage ?
+ -1:
+ (int)Math.Ceiling ((double)page1.Slot.Width / (double)itemPerPage * (double)(data.Count+1)):
+ data.Count < itemPerPage ?
+ -1:
+ (int)Math.Ceiling ((double)page1.Slot.Height / (double)itemPerPage * (double)(data.Count+1));
}
}
-
void itemClick(object sender, OpenTK.Input.MouseButtonEventArgs e){
SelectedIndex = data.IndexOf((sender as GraphicObject).DataSource);
}