ListView button column not working
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!
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!
Code: Select all
<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>
Code: Select all
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());
}
}
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: ListView button column not working
Hi, the problem is with the Command binding. You are specifying:
But the name of your root control (which contains the context exposing the DeleteCommand) is "ButtonsControl", so the binding should be:
Code: Select all
<Button Command="{Binding Path=DataContext.DeleteCommand, ElementName=DetailsController}".../>
Code: Select all
<Button Command="{Binding Path=DataContext.DeleteCommand, ElementName=ButtonsControl}".../>
Re: ListView button column not working
Yeah! Its working awesome!
Thank you very much!
Thank you very much!
Re: ListView button column not working
Closing this!
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot], Semrush [Bot] and 71 guests