fixer007
Topic Author
Posts: 2
Joined: 02 Oct 2017, 11:40

ListView button column not working

14 Oct 2017, 09:48

Hi Noesis community!
i've try to use the code shown at this topic: viewtopic.php?f=3&t=1176 But its not working in my case. on the button click the command function should be executed, but its not. I have try many ways to solve it, but its still not working. Please, help me, i think there is a simple solution, but i cant see it as i beginner in using Noesis and WPF. My Unity3D version is 5.6.0f3 and Noesis version is 2.1.0b4. Project archive in Google Drive: https://drive.google.com/file/d/0Bx-F4L ... sp=sharing
Thank you!
<Grid
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
    x:Name="ButtonsControl" Height="190.345" Width="241.799">

    <ListView ItemsSource="{Binding MPValues}">
        <ListView.View>
            <GridView>
                <GridViewColumn  Header="#" DisplayMemberBinding="{Binding LiteralIndex}"/>

                <GridViewColumn >
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <Button  Command="{Binding Path=DataContext.DeleteCommand, ElementName=DetailsController}" CommandParameter="{Binding LiteralIndex}" Content="Delete" />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>
</Grid>

using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using UnityEngine;
using Noesis.Samples;

public class Item
{
    public int LiteralIndex { get; set; }
}

public class Context
{
    public DelegateCommand DeleteCommand { get; private set; }
    public ObservableCollection<Item> MPValues { get; private set; }

    public Context()
    {
        DeleteCommand = new DelegateCommand(OnDelete);
        MPValues = new ObservableCollection<Item>();

        for (int i = 0; i < 20; ++i)
        {
            MPValues.Add(new Item { LiteralIndex = i });
        }
    }

    private void OnDelete(object param)
    {
        int literalIndex = (int)param;
        int numItems = MPValues.Count;
        for (int i = 0; i < numItems; ++i)
        {
            Item item = MPValues[i];
            if (item.LiteralIndex == literalIndex)
            {
                MPValues.RemoveAt(i);
                break;
            }
        }
    }
}

public class TestBehavior : MonoBehaviour
{
    void Start()
    {
        var gui = GetComponent<NoesisView>();
        gui.Content.DataContext = new Context();

        Debug.Log(gui.Content.DataContext.ToString());

 
    }
}
 
User avatar
sfernandez
Site Admin
Posts: 1935
Joined: 22 Dec 2011, 19:20

Re: ListView button column not working

18 Oct 2017, 22:27

Hi, the problem is with the Command binding. You are specifying:
<Button Command="{Binding Path=DataContext.DeleteCommand, ElementName=DetailsController}".../>
But the name of your root control (which contains the context exposing the DeleteCommand) is "ButtonsControl", so the binding should be:
<Button Command="{Binding Path=DataContext.DeleteCommand, ElementName=ButtonsControl}".../>
 
fixer007
Topic Author
Posts: 2
Joined: 02 Oct 2017, 11:40

Re: ListView button column not working

28 Oct 2017, 14:36

Yeah! Its working awesome!
Thank you very much!
 
User avatar
jsantos
Site Admin
Posts: 2923
Joined: 20 Jan 2012, 17:18
Contact:

Re: ListView button column not working

28 Oct 2017, 14:54

Closing this!

Who is online

Users browsing this forum: No registered users and 3 guests