WPF 控件就像收藏夹栏

标签 wpf visual-studio

我试图弄清楚收藏夹栏在 IE/Firefox 等中是什么样的控件。基本上,您可以在视觉上存储书签、移动、轻松删除。

我试过用 ToolBar 做一些事情,虽然我可以添加按钮并使它们像我想要的那样工作,但删除和重新排列它们是有问题的。我也尝试过 ListView ,但事实证明让它们正确显示很困难。也许像大图标 View ,没有图标。

我只是在寻找一些东西,人们可以在其中为导航页面添加书签以返回到他们之前查看的页面。

编辑:
我想我真的不太关心重新排列。我只是想弄清楚如何

  • 以编程方式添加它们
  • 使它们可点击,使用点击事件
  • 当我不再需要它们时删除它们

  • 我试过这个作为测试:
        <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>
    

    但我什至不能选择任何一个 listviewitems,更不用说点击它们了。如果我右键单击一个,它不会告诉我我在上下文菜单事件处理程序中单击了哪一个。
    这令人沮丧,因为在 WinForms 中我已经完成了这项工作。我迫不及待地等到我已经拿起足够多的东西,这样 WPF 才开始点击。我觉得我又要从 VB6 转向 VB.Net,但更是如此。

    最佳答案

    所以我想我让它按照我想要的方式工作,减去重新排序。
    我现在可以忍受。

    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
    

    这提供了在 WPF 窗口中添加和删除书签的框架和 ListView 作为书签栏。我愿意接受改进它的建议或更好的方法。

    关于WPF 控件就像收藏夹栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5837477/

    相关文章:

    c# - WPF `ComboBox` ItemsSource 属性已更改 SelectedItem 属性被设置为 null

    c# - WebRequest 使用 Mozilla Firefox

    c# - WPF :Material Design + dragablz tabItem header style

    visual-studio - Visual Studio中有没有选择当前行的快捷方式?

    c# - 遍历列表并将值添加到二维数组

    c++ - visual c++ 跨平台android : Include prebuilt shared library

    visual-studio - Visual Studio 2015 - 用户任务消失了?

    wpf - wpf 窗口顶部的空白区域

    c# - WPF 应用程序在关闭主窗口时不会关闭

    visual-studio - 回滚整个变更集表示没有回滚更改