<?xml version="1.0" encoding="utf-8"?>
<Resource>
  <Folder name="GacGenConfig">
    <Folder name="ResX86">
      <Text name="Resource">..\..\UIRes\32bits\control_list_listview_bindable.bin</Text>
    </Folder>
    <Folder name="ResX64">
      <Text name="Resource">..\..\UIRes\64bits\control_list_listview_bindable.bin</Text>
    </Folder>
  </Folder>
  <Image content="File">Book16.png</Image>
  <Image content="File">Book32.png</Image>
  <Image content="File">Open16.png</Image>
  <Image content="File">Open32.png</Image>
  <Folder name="MainWindow">
    <Script name="ViewModel">
      <Workflow><![CDATA[
        module viewmodel;
        using system::*;
        using presentation::*;

        namespace sample
        {
          class BookItem
          {
            prop Title : string = Sys::LoremIpsumTitle(24) {not observe}
            prop Author : string = Sys::LoremIpsumTitle(16) {not observe}
            prop DatePublished : DateTime = {} {not observe}
            prop Summary : string = Sys::LoremIpsumTitle(64) {not observe}
            prop Content : string = Sys::LoremIpsumTitle(512) {not observe}
            prop SmallImage : GuiImageData^ = null {not observe}
            prop LargeImage : GuiImageData^ = null {not observe}
          }
        }
      ]]></Workflow>
    </Script>
    <Instance name="MainWindowResource">
      <Instance ref.Class="sample::MainWindow">
        <ref.Members><![CDATA[
          @cpp:Private
          var views: ListViewView[] = {
            ListViewView::BigIcon;
            ListViewView::SmallIcon;
            ListViewView::List;
            ListViewView::Tile;
            ListViewView::Information;
            ListViewView::Detail;
          };

          @cpp:Private
          var books: observe BookItem^[] = {};
          @cpp:Private
          var lastSelectedItem: int = -1;

          @cpp:Private
          var iconBook16: ImageData^ = null;
          @cpp:Private
          var iconBook32: ImageData^ = null;
          @cpp:Private
          var iconOpen16: ImageData^ = null;
          @cpp:Private
          var iconOpen32: ImageData^ = null;

          func FormatDate(date: DateTime): string
          {
            var locale = Application::GetApplication().Locale;
            var formats = Localization::GetLongDateFormats(locale).CreateEnumerator();
            formats.Next(); 
            var format = cast string formats.Current;
            return Localization::FormatDate(locale, format, date);
          }
        ]]></ref.Members>
        <ref.Ctor><![CDATA[
          {
            self.iconBook16 = cast (ImageData^) self.ResolveResource("res", "Book16.png", true);
            self.iconBook32 = cast (ImageData^) self.ResolveResource("res", "Book32.png", true);
            self.iconOpen16 = cast (ImageData^) self.ResolveResource("res", "Open16.png", true);
            self.iconOpen32 = cast (ImageData^) self.ResolveResource("res", "Open32.png", true);


            for (i in range [0, 24))
            {
              var book = new BookItem^();
              book.DatePublished = Sys::CreateDateTime(2010 + i / 3, 1 + i / 2, 1 + i);
              book.SmallImage = self.iconBook16;
              book.LargeImage = self.iconBook32;
              self.books.Add(book);
            }
          }
        ]]></ref.Ctor>
        <Window ref.Name="self" Text="control_list_listview_bindable" ClientSize="x:640 y:480">
          <Table AlignmentToParent="left:0 top:0 right:0 bottom:0" CellPadding="5" BorderVisible="false" MinSizeLimitation="LimitToElementAndChildren">
            <att.Rows>
              <CellOption>composeType:MinSize</CellOption>
              <CellOption>composeType:Percentage percentage:1.0</CellOption>
            </att.Rows>
            <att.Columns>
              <CellOption>composeType:MinSize</CellOption>
              <CellOption>composeType:Absolute absolute:120</CellOption>
              <CellOption>composeType:Percentage percentage:1.0</CellOption>
            </att.Columns>

            <Cell Site="row:0 column:0">
              <Table AlignmentToParent="left:0 top:0 right:0 bottom:0" CellPadding="5" BorderVisible="false" MinSizeLimitation="LimitToElementAndChildren">
                <att.Rows>
                  <CellOption>composeType:Percentage percentage:0.5</CellOption>
                  <CellOption>composeType:MinSize</CellOption>
                  <CellOption>composeType:Percentage percentage:0.5</CellOption>
                </att.Rows>
                <att.Columns>
                  <CellOption>composeType:Percentage percentage:1.0</CellOption>
                </att.Columns>
                <Cell Site="row:1 column:0">
                  <Label Text="listView.View = ListViewView::"/>
                </Cell>
              </Table>
            </Cell>

            <Cell Site="row:0 column:1">
              <ComboBox ref.Name="comboView" SelectedIndex="0">
                <att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
                <att.ListControl>
                  <TextList HorizontalAlwaysVisible="false" VerticalAlwaysVisible="false">
                    <att.Items>
                      <TextItem Text="BigIcon"/>
                      <TextItem Text="SmallIcon"/>
                      <TextItem Text="List"/>
                      <TextItem Text="Tile"/>
                      <TextItem Text="Information"/>
                      <TextItem Text="Detail"/>
                    </att.Items>
                  </TextList>
                </att.ListControl>
              </ComboBox>
            </Cell>
            
            <Cell Site="row:1 column:0 columnSpan:3">
              <Table AlignmentToParent="left:0 top:0 right:0 bottom:0" CellPadding="5" BorderVisible="false" MinSizeLimitation="LimitToElementAndChildren">
                <att.Rows>
                  <CellOption>composeType:MinSize</CellOption>
                  <CellOption>composeType:MinSize</CellOption>
                  <CellOption>composeType:MinSize</CellOption>
                  <CellOption>composeType:MinSize</CellOption>
                  <CellOption>composeType:Percentage percentage:1.0</CellOption>
                </att.Rows>
                <att.Columns>
                  <CellOption>composeType:Absolute absolute:400</CellOption>
                  <CellOption>composeType:MinSize</CellOption>
                  <CellOption>composeType:Percentage percentage:1.0</CellOption>
                </att.Columns>

                <ColumnSplitter ColumnsToTheLeft ="1"/>

                <Cell Site="row:0 column:0 rowSpan:5">
                  <BindableListView ref.Name="listView" View-bind="self.views[comboView.SelectedIndex]" HorizontalAlwaysVisible="false" VerticalAlwaysVisible="false" env.ItemType="sample::BookItem^" env.ItemName="item">
                    <att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
                    <att.ItemSource-eval>self.books</att.ItemSource-eval>
                    <att.LargeImageProperty>SmallImage</att.LargeImageProperty>
                    <att.SmallImageProperty>LargeImage</att.SmallImageProperty>
                    <att.Columns>
                      <ListViewColumn Text="Title" TextProperty="Title"/>
                      <ListViewColumn Text="Author" TextProperty="Author" SortingState="Ascending"/>
                      <ListViewColumn Text="Date Published" TextProperty="self.FormatDate(item.DatePublished)" SortingState="Descending"/>
                      <ListViewColumn Text="Summary" TextProperty="Summary">
                        <att.DropdownPopup>
                          <ToolstripMenu>
                            <MenuItemButton Text="Fake"/>
                            <MenuItemButton Text="Menu"/>
                            <MenuItemButton Text="Item"/>
                          </ToolstripMenu>
                        </att.DropdownPopup>
                      </ListViewColumn>
                    </att.Columns>
                    <att.DataColumns>
                      <_>0</_>
                      <_>1</_>
                    </att.DataColumns>

                    <ev.SelectionChanged-eval><![CDATA[
                      {
                        var last = self.lastSelectedItem;
                        var current = listView.SelectedItemIndex;
                        self.lastSelectedItem = current;

                        Application::GetApplication().InvokeInMainThread(self, func():void
                        {
                          if (last != -1)
                          {
                            self.books[last].SmallImage = self.iconBook16;
                            self.books[last].LargeImage = self.iconBook32;
                            self.books.ItemChanged(last, 1, 1);
                          }
                          if (current != -1)
                          {
                            self.books[current].SmallImage = self.iconOpen16;
                            self.books[current].LargeImage = self.iconOpen32;
                            self.books.ItemChanged(current, 1, 1);
                          }
                        });
                      }
                    ]]></ev.SelectionChanged-eval>
                  </BindableListView>
                </Cell>

                <Cell Site="row:0 column:1">
                  <Label Text-eval="listView.Columns[0].Text"/>
                </Cell>
                <Cell Site="row:1 column:1">
                  <Label Text-eval="listView.Columns[1].Text"/>
                </Cell>
                <Cell Site="row:2 column:1">
                  <Label Text-eval="listView.Columns[2].Text"/>
                </Cell>
                <Cell Site="row:3 column:1">
                  <Label Text-eval="listView.Columns[3].Text"/>
                </Cell>

                <Cell Site="row:0 column:2">
                  <DocumentTextBox EditMode="Selectable" Text-bind="(cast (BookItem^) listView.SelectedItem).Title ?? ''">
                    <att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
                  </DocumentTextBox>
                </Cell>
                <Cell Site="row:1 column:2">
                  <DocumentTextBox EditMode="Selectable" Text-bind="(cast (BookItem^) listView.SelectedItem).Author ?? ''">
                    <att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
                  </DocumentTextBox>
                </Cell>
                <Cell Site="row:2 column:2">
                  <DocumentTextBox EditMode="Selectable" Text-bind="self.FormatDate((cast (BookItem^) listView.SelectedItem).DatePublished) ?? ''">
                    <att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
                  </DocumentTextBox>
                </Cell>
                <Cell Site="row:3 column:2">
                  <DocumentTextBox EditMode="Selectable" Text-bind="(cast (BookItem^) listView.SelectedItem).Summary ?? ''">
                    <att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
                  </DocumentTextBox>
                </Cell>
                <Cell Site="row:4 column:1 columnSpan:2">
                  <DocumentViewer EditMode="Selectable" HorizontalAlwaysVisible="false" VerticalAlwaysVisible="false" Text-bind="(cast (BookItem^) listView.SelectedItem).Content ?? ''">
                    <att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
                  </DocumentViewer>
                </Cell>
              </Table>
            </Cell>
          </Table>
        </Window>
      </Instance>
    </Instance>
  </Folder>
</Resource>