[solved] ListView command binding and Item labels (1 Viewer)

FreakyJ

Development Group
  • Team MediaPortal
  • July 25, 2010
    4,024
    1,420
    Germany Germany
    Country flag
    • Thread starter
    • Moderator
    • #1
    @morpheus_xx
    I thought I would start working on a little Inputmanager, because this is requested by many people :)
    It is a bit how you doing, but anyway^^

    First problem:
    I can add Items to the Listview and the Items shown, but without any text :( I tried to read in other plugins, but I think I did it exactly the same, but it just doesn't work :/
    See attached Screenshot.
    The code looks liek this:
    XML:
    <?xml version="1.0" encoding="utf-8"?>
    <Include
        xmlns="www.team-mediaportal.com/2008/mpf/directx"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Source="screens\master_menu.xaml"
        >
        <Include.Resources>
            <ControlTemplate x:Key="Contents_Template">
            <Grid>
                <!-- Model = MediaNavigationModel -->
                <Grid.Resources>
                    <Model x:Key="MediaModel" Id="CC11183C-01A9-4F96-AF90-FAA046981006"/>
                </Grid.Resources>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsVisible="true">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
    
                        <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>
                                <!--<Command x:Key="Menu_Command" Source="{StaticResource MediaModel}" Path="Select"
                    Parameters="{LateBoundValue BindingValue={Binding}}"/>-->
                                <CommandBridge x:Key="Menu_Command" Command="{Binding Path=Command,Mode=OneTime}"/>
                            </ListView.Resources>
                        </ListView>
                        <Button Context="{Model Id=CC11183C-01A9-4F96-AF90-FAA046981006}" Content="Add" Style="{ThemeResource ButtonWideStyle}" Margin="10"
                  HorizontalAlignment="Right" VerticalAlignment="Center"
                  Command="{Command AddKeyMapping}"/>
                    </Grid>
            </Grid>
            </ControlTemplate>
        </Include.Resources>
    </Include>
    And the creation of the ListItems:

    Code:
    protected ItemsList _items;
    public ItemsList Items
        {
          get { return _items; }
        }
    
    private void InitModel()
        {
    _items = new ItemsList();
    
    [....]
    
    var tmp = new ListItem();
            tmp.SetLabel("asdda", "sadas");
            tmp.SetLabel("dsfsdf", "adsadsda");
            tmp.SetLabel("dsadsa", "asdasfds");
            //tmp.Command = new MethodDelegateCommand(() => ChooseKeyAction(someString));
            _items.Add(tmp);
            _items.Add(new ListItem("cdgdfgdfgdfgdfg", "ddgdfgdfg"));
            _items.FireChange();
    }
    The second Issue is that I get the following message:
    [2015-09-25 13:26:37,722] [56639 ] [InputMgr ] [WARN ] - CommandBaseMarkupExtension: Could not find method, could not execute command ({Command Source=MediaPortal.Plugins.Inputmanager.Models.ConfigScreen,Path=Select})
    The code:
    XML:
    <?xml version="1.0" encoding="utf-8"?>
    <Include
        xmlns="www.team-mediaportal.com/2008/mpf/directx"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Source="screens\master_menu.xaml"
        >
        <Include.Resources>
            <ControlTemplate x:Key="Contents_Template">
                <Grid>
                    <!-- Model = MediaNavigationModel -->
                    <Grid.Resources>
                        <Model x:Key="MediaModel" Id="CC11183C-01A9-4F96-AF90-FAA046981006"/>
                    </Grid.Resources>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsVisible="true">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
    
                        <ListView Context="{Model Id=CC11183C-01A9-4F96-AF90-FAA046981006}" Style="{StaticResource ContentsMenuListViewStyle}" ItemsSource="{Binding Path=ActionItems,Mode=OneTime}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsVisible="true">
                            <ListView.Resources>
                                <Command x:Key="Menu_Command" Source="{StaticResource MediaModel}" Path="Select"
                    Parameters="{LateBoundValue BindingValue={Binding}}"/>
                            </ListView.Resources>
                        </ListView>
                        <Button Context="{Model Id=CC11183C-01A9-4F96-AF90-FAA046981006}" Content="Finish" Style="{ThemeResource ButtonWideStyle}" Margin="10"
                  HorizontalAlignment="Right" VerticalAlignment="Center"
                  Command="{Command AddKeyFinish}"/>
                    </Grid>
                </Grid>
            </ControlTemplate>
        </Include.Resources>
    </Include>
    This is how I generate the items (you are probably screaming how I select the properties from "Key" :D
    Code:
    _actionItems = new ItemsList();
          foreach (var property in typeof(Key).GetFields())
          {
            var listItem = new ListItem(property.Name, property.Name);
            listItem.Command = new MethodDelegateCommand(() => ChooseKeyAction(property.Name));
            _actionItems.Add(listItem);
            ServiceRegistration.Get<ILogger>().Info("Action: {0}", property.Name);
          }
     

    Attachments

    FreakyJ

    Development Group
  • Team MediaPortal
  • July 25, 2010
    4,024
    1,420
    Germany Germany
    Country flag
    • Thread starter
    • Moderator
    • #3
    Thank you for your answer :) I was already looking for hours into this, finally I've found it, the first value for ListItem has to be "Name": new ListItem("Name", "THE LABEL TEXT").

    The second issue is still present. I will keep trying to fix it by my own, but if you have an idea I would be really thankful :)
    The plugin is already working very well. I can map combinations of keys to actions defined in Key from within the GUI. And it is using raw inputs that means you can map "strg+s" from your keyboard to another action than "strg + s" from your remote :)
     

    morpheus_xx

    Lead Dev MP2
  • Team MediaPortal
  • March 24, 2007
    11,400
    6,971
    Germany Germany
    Country flag
    Use the Const.KEY_NAME as key, then the default list view style will show this text.
    Code:
    new ListItem(Consts.KEY_NAME, "text")
    The Key class has a property: NAME2SPECIALKEY which contains the special keys. Any plugin can define own keys, they will be added there in CTOR of Key class.

    Then also please look for the (I)InputManager service/interface, which is the public interface for handling "keys".

    Will be away over weekend.
     

    FreakyJ

    Development Group
  • Team MediaPortal
  • July 25, 2010
    4,024
    1,420
    Germany Germany
    Country flag
    • Thread starter
    • Moderator
    • #5
    Thank you :)
    So I was just slightly faster^^ As you see I already got this working, only problem left is the second one.
    [2015-09-25 13:26:37,722] [56639 ] [InputMgr ] [WARN ] - CommandBaseMarkupExtension: Could not find method, could not execute command ({Command Source=MediaPortal.Plugins.Inputmanager.Models.ConfigScreen,Path=Select})
    Then also please look for the (I)InputManager service/interface, which is the public interface for handling "keys".
    Yes I am using this already to send the special keys to the GUI :)
    I basically map keyboard presses to special keys. For example: "strg + h" gets mapped to Key.F11.
    If the user now presses "strg + h" I send Key.F11 using ServiceRegistration.Get<IInputManager>().KeyPress(Key.Something) to send the action to the GUI :)
     

    FreakyJ

    Development Group
  • Team MediaPortal
  • July 25, 2010
    4,024
    1,420
    Germany Germany
    Country flag
    • Thread starter
    • Moderator
    • #6
    I've found the solution :)
    XML:
    <CommandBridge x:Key="Menu_Command" Command="{Binding Path=Command,Mode=OneTime}" />
    Thank you very much for you help (y)
     

    ge2301

    MP2 Design
  • Team MediaPortal
  • January 11, 2014
    6,622
    2,387
    Stuttgart
    Germany Germany
    Country flag
    (y) looking forward trying this one. Target is allow the user fully mapping keys in GUI? that would be great!
     

    FreakyJ

    Development Group
  • Team MediaPortal
  • July 25, 2010
    4,024
    1,420
    Germany Germany
    Country flag
    • Thread starter
    • Moderator
    • #8
    I don't recommend using it yet, but if want to have a peak :)
    My main problem is that I don't know xaml and I don't know all the MP GUI stuff... This is also the main reason why I am a bit reluctant to help you :(
    If you try it, you know what I mean :D I really prefer to work with the backend^^ The last part of the config is not finished, so if you are mapping a key you are kind of stuck in the gui, also the Menu:x options aren't working that good right now :whistle:

    Edit:
    Removed attachment
     
    Last edited:

    ge2301

    MP2 Design
  • Team MediaPortal
  • January 11, 2014
    6,622
    2,387
    Stuttgart
    Germany Germany
    Country flag
    I know a little bit xaml meanwhile, not enough to create perfect innovative things, but enough to survive :)
    Working with the backend is what I can not do anymore. I could use a bit #C, but it's too long time ago and I forgot most things. So there is not problem. I'd like to help with some xaml stuff, but only after coming back from vacation and that is October. I'll try your code then and see, if I can contribute somehow (y)

    The other things we talked about (e.g. new or favorite flags) is really only about backend code. There I'm lost :whistle:
     

    Stéphane Lenclud

    Development Group
  • Team MediaPortal
  • April 29, 2013
    2,563
    1,288
    Germany Germany
    Country flag
    Nice to see someone is working on that :)
    Ideally we would need to map actions/commands as published by plug-ins to N key input.

    I believe that requires quite bit of architectural changes in the input manager and plug-ins.
     

    Users Who Are Viewing This Thread (Users: 0, Guests: 1)

    Top Bottom