Andreas Schooll
Topic Author
Posts: 25
Joined: 30 Sep 2013, 16:58

ListView / ListBox with a Button in each Line

04 Oct 2013, 11:44

Hi there,

we have several cases in our UI design, where we have a Button in each line of a ListView or ListBox. In example a delete Button to Delete something associated with the line.

I found a good example how this is normally done in XAML / WPF:
http://stackoverflow.com/questions/7127 ... -each-line

I read in the forums that
<Button Click="Button_Click">X</Button>
will currently not work with Noesis and Unity. Is that a fact?

What would be a good workaround to achieve our goal?

best regards,
Andreas
 
golgepapaz
Posts: 43
Joined: 01 Aug 2013, 01:59

Re: ListView / ListBox with a Button in each Line

04 Oct 2013, 19:17

if you know the button name there is a example to how to register click callbacks to a button at runtime.
viewtopic.php?f=3&t=156
 
User avatar
sfernandez
Site Admin
Posts: 3203
Joined: 22 Dec 2011, 19:20

Re: ListView / ListBox with a Button in each Line

05 Oct 2013, 17:43

A good way to implement what you need is by using commands.

- The class that describes your items will expose a property for each command you need: EditItemCommand, DeleteItemCommand, ... (like the DelegateCommand we exposed in our Commands sample in NoesisGUI package).

- Then your DataTemplate will include a Button for each command you want to execute binded to the corresponding item's command property, for example:
<DataTemplate>
    <StackPanel Orientation="Horizontal">
        <TextBlock Text="{Binding ItemName}"/>
        <Button Content="Edit" Command="{Binding ItemEditCommand}"/>
        <Button Content="Delete" Command="{Binding ItemDeleteCommand}"/>
    </StackPanel>
</DataTemplate>
But other user reported a bug about this scenario that needs to be solved before you can do it that way. We will let you know when it is fixed.

Sorry for the inconvenience :oops:
 
Andreas Schooll
Topic Author
Posts: 25
Joined: 30 Sep 2013, 16:58

Re: ListView / ListBox with a Button in each Line

07 Oct 2013, 13:00

Hey, thanks for your replies.

@golgepapaz:
We also thought about installing the click-function manually. But as the listitems get created manually we would need some kind of callback to access those list elements to get to the buttons. Or iterate through all elements after something in the list changes. But i don't know if this is a reasonable approach?

@sfernandez
Do you think this will be fixed within the next 2 weeks?

Would it work if we created a UserControl for a listelement that has its own xaml and c# code. In the c# code we could easily access the button. Do ListViews work with UserControls in the Datatempalte?

best regards,
Andreas
 
User avatar
jsantos
Site Admin
Posts: 4219
Joined: 20 Jan 2012, 17:18
Contact:

Re: ListView / ListBox with a Button in each Line

09 Oct 2013, 05:12

@sfernandez
Do you think this will be fixed within the next 2 weeks?
Yes, at least it is planned.

Who is online

Users browsing this forum: Semrush [Bot] and 2 guests