XAML Desktop Listbox event data 2023r3

The Tag in the parameters is always empty when selecting/clicking an item in the listbox.

Reproduce by creating a xaml listbox object and a textarea on a window and the following event on the xaml object.

Event Triggered code on XAML Container:

Sub EventTriggered(eventName As String, parameters As Dictionary) Handles EventTriggered
  Dim s As String = eventName + EndOfLine
  For Each d As DictionaryEntry In parameters
    s=s + d.Key + ": " + d.Value + EndOfLine
  Next
  TextArea1.Text = s +  TextArea1.Text //newest event at top
End Sub
1 Like

Fix: Adding the items to the listbox this way both gives me the Tag value and an Index value as well.

<ScrollViewer>
	<ListBox Name='ListBox' BorderThickness='1.0' SelectedIndex='0'>
        <ListBoxItem Content="Coffie" Tag="Coffee"></ListBoxItem>
        <ListBoxItem Content="Tea" Tag="Tea"></ListBoxItem>
        <ListBoxItem Content="Orange Juice" Tag="Orange Juice"></ListBoxItem>
        <ListBoxItem Content="Milk" Tag="Milk"></ListBoxItem>
    </ListBox>
</ScrollViewer>

Have you also tried to implement MultiColumn, Folders and Events like DoublePressed, ContextualMenu’s and alike?

You can do multicolumn etc. I am not familiar with Microsoft XAML at all, and am just playing around. I do not know how to get it to trigger events on double-click or right click etc, and usually when you are using xaml, you have access to bindings which enable events and make adding data easier. Xojo need to extend this a bit more, and provide more samples.

<ListBox Name="ListBox1" BorderThickness="1.0" SelectedIndex="1" Margin="5">
    <!-- Define the ListBoxItem -->
    <ListBoxItem>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            
            <!-- Manually set content for each column -->
            <TextBlock Text="Apples" Grid.Column="0" Margin="5"/>
            <TextBlock Text="Red" Grid.Column="1" Margin="5"/>
            <TextBlock Text="$0.99" Grid.Column="2" Margin="5"/>
        </Grid>
    </ListBoxItem>

    <!-- Repeat for other items -->
    <ListBoxItem>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            
            <TextBlock Text="Oranges" Grid.Column="0" Margin="5"/>
            <TextBlock Text="Orange" Grid.Column="1" Margin="5"/>
            <TextBlock Text="$0.79" Grid.Column="2" Margin="5"/>
        </Grid>
    </ListBoxItem>

    <ListBoxItem>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            
            <TextBlock Text="Bananas" Grid.Column="0" Margin="5"/>
            <TextBlock Text="Yellow" Grid.Column="1" Margin="5"/>
            <TextBlock Text="$0.59" Grid.Column="2" Margin="5"/>
        </Grid>
    </ListBoxItem>
</ListBox>
2 Likes

Thank you for sharing this with us @Daniel_Mullins :slight_smile: