Windows Universal App (XAML): ListviewItem on selected advanced view (Show button only when ListViewItemsis selected

Question!

I'm working on my first Universal App (I'm beginner with it).

In app I have few places, where I want to select ListViewItem, and remove/edit (http://i.imgur.com/ZRkIQHm.png) it by some button. I'm not a designer, so I want to choose some simple, good-looking solution how to display these buttons.

I was inspired by Windows 10, there are few places, where you click on ListViewItem, and this selected item shows some buttons (Printer setting, WiFi connection, Bluetooth connection) - like on this image - http://i.imgur.com/WjerA5F.png.

I've spend lot of time with googling, trying, and now I have no idea how to do it. I was closest probably with using VisualStateManager in ListViewItemContainer.

Here is code example (in c# is filled ItemsSource by some ObservableCollection<>):

<ListView Name="dbList" Grid.Column="0" SelectionChanged="dbList_SelectionChanged">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal" Name="XXX">
                            <TextBlock Text="{Binding}"/>
                            <Button Name="removeDatabaseButton" Click="removeDatabaseButton_Click" Content="Remove" Tag="{Binding}"/>
                        </StackPanel>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

Thanks!

PS: Sorry for my english :)



Answers

The answer is quite complicated:

You need to modify your list Type Class which should implement the INotifyPropertyChanged interface which has the property Visible.

 private Visibility _visible;

    public Visibility Visible //Binding to this in Listbox - Button Visibility
    {
        get { return _visible; }
        set { _visible = value; } //Call OnPropertyChanged method
    }

Now create a listview_itemclick() method. Call the listview.selectedindex and set the visibility of the listitem property "Visible" to Visible - the event PropertyChanged will fire and the ui gets notified that the visibility of this specific button should change.

Helping links:

INotifyPropertyChangedInterface

Playlist to MVVM tutorials - containing INotifyPropertyChanged



This video can help you solving your question :)
By: admin