Untergeordnete Seiten
  • Dynamic ListView - basics

  Wiki Navigation

    Loading...


 Recently Updated


 Latest Releases

 MediaPortal 1.32
            Releasenews | Download
 MediaPortal 2.5
            Releasenews | Download


Table of Contents

Overview

This page gives a short overview how to use the ListView Element.

Main points shown here are:

  • Add items to the ListView dynamically
  • Bind a action to each item

Sample

XAML code:

<ListView Context="{Model Id=CC11183C-01A9-4F96-AF90-FAA046981006}" Style="{StaticResource ContentsMenuListViewStyle}"
 ItemsSource="{Binding Path=Items,Mode=OneTime}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsVisible="true">
  <ListView.Resources>
    <CommandBridge x:Key="Menu_Command" Command="{Binding Path=Command,Mode=OneTime}" />
  </ListView.Resources>
</ListView>

 

Context defines the ID of the Model where the resource used by this element is defines.

ItemsSource defines the property Name used in Model.

The Tag CommandBridge is responsible for binding the Click action to a function defined in the Model.

 

C# code:

protected ItemsList _items = new ItemsList();
// The name "Items" is also defined above in ItemsSource: "Path=Items"
public ItemsList Items
{
  get { return _items; }
}

// this could be a function called anywhere in the workflow.
// In this example this function gets called while the Model gets initialized (not shown here)
private void InitModel()
{
  // we define a new ListItem which we would like to add to the ListView
  var item = new ListItem();
  // We give it a name which si shown in the List
  item.SetLabel(Consts.KEY_NAME, "This text shows up in the List as Name");
  // now we a add a command, you don't have to pass a string,
  // it could be anything as long as you change the function definition probably
  // also the value of the string can be different for each item
  string stringToPass = "some string";
  item.Command = new MethodDelegateCommand(() => ItemClicked(stringToPass));
  // add the item to the list
  _items.Add(item);
  // tell the skin that the List has changed
  _items.FireChange();
}

// change the function definition here, e.g. change string to int
public void ItemClicked(string passedString) {
  // do something with the passed value
}

 

 

Remarks

This is only an introduction and there might be more features which are not explained here.

Related

   

 

This page has no comments.