WPF Controls, such as Favorites Bar

I am trying to figure out what the favorites panel is in IE / Firefox, etc. Basically, you can visually store bookmarks, navigate and easily delete.

I tried to do something using the ToolBar, and although I can add buttons and make them work the way I want, deleting and reordering them is problematic. I also tried lists, but displaying them correctly is difficult. Perhaps something like a large icon, without icons.

I'm just looking for something where people can add navigation pages to get back to what they were looking at before.

Edit:
I guess I donโ€™t even care about rearranging it all. I'm just trying to figure out how

  • Add them progmatically
  • Make them clickable with the click event
  • Remove them when I don't want them anymore

I tried this as a test:

<ListView Grid.Row="1" Name="ListView1"> <WrapPanel> <WrapPanel.ContextMenu> <ContextMenu> <MenuItem Name="mnuDelete" Header="Delete" /> </ContextMenu> </WrapPanel.ContextMenu> <Button Name="AddSite">+</Button> <ListViewItem Content="Test 1" /> <ListViewItem Content="Test 2" /> </WrapPanel> </ListView> 

But I canโ€™t even select any of the listviewitems, let alone click on them. If I right-click one at a time, this does not tell me which one I clicked on in the context menu event handler.
This is frustrating because in WinForms I would already do that. I canโ€™t wait until I picked up enough for WPF to just start pushing. It seems to me that I am again moving from VB6 to VB.Net, but even more so.

+6
source share
1 answer

So, I think I worked the way I want, minus reordering.
I can live with it for now.

XAML:

 <Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Tracks" Height="350" Width="525"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="20" /> <RowDefinition Height="26" /> <RowDefinition Height="265*" /> </Grid.RowDefinitions> <Menu Name="Menu1" /> <Frame Grid.Row="2" Name="Frame1" Source="PageSearchResults.xaml" /> <StackPanel Orientation="Horizontal" Grid.Row="1"> <Button Name="AddSite">+</Button> <ListView Name="ListView1" MouseDoubleClick="ListViewItem_MouseDoubleClick"> <ListView.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </ListView.ItemsPanel> <ListView.ContextMenu> <ContextMenu> <MenuItem Name="mnuDelete" Header="Delete" /> </ContextMenu> </ListView.ContextMenu> </ListView> </StackPanel> </Grid> </Window> 

VB:

 Class MainWindow Dim bookmarks As New ArrayList Private Sub mnuDelete_click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles mnuDelete.Click If Not ListView1.SelectedValue Is Nothing Then bookmarks.RemoveAt(ListView1.SelectedValue) End If ListView1.Items.RemoveAt(ListView1.SelectedIndex) End Sub Private Sub AddSite_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles AddSite.Click Dim i As Integer = 0 Dim itmX As Integer Dim itm As New ListViewItem i = bookmarks.Add(Frame1.Content) itmX = ListView1.Items.Add(New DictionaryEntry(i, Frame1.Content.title)) ListView1.DisplayMemberPath = "Value" ListView1.SelectedValuePath = "Key" End Sub Private Sub ListViewItem_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) If Not ListView1.SelectedValue Is Nothing Then Frame1.Content = bookmarks(ListView1.SelectedValue) End If End Sub End Class 

And this adds and removes bookmarks in the WPF window with the frame and list as a bookmarks bar. I am open to suggestions for improving it or the best ways to do it.

+1
source

Source: https://habr.com/ru/post/886986/


All Articles