以编程方式在wpf中添加按钮到工具栏

man*_*ske 1 c# browser wpf button

我正在尝试向我的浏览器添加书签功能,但我无法弄清楚如何将我创建的按钮添加到工具栏.

我在XAML中定义的工具栏:

<ToolBar x:Name="Bookbar" HorizontalAlignment="Left" VerticalAlignment="Top" Width="799" Height="36">

        </ToolBar>
Run Code Online (Sandbox Code Playgroud)

以及我尝试将创建的按钮添加到工具栏的c#代码:

private void Bookmark_Click(object sender, RoutedEventArgs e) //add bookmark
    {
        if (Urlbox.Text.Contains("http://") == false)
        {
            bookmarks = Microsoft.VisualBasic.Interaction.InputBox("Please insert your new bookmark", "New Bookmark", "http://" + Urlbox.Text);

        }
        else
        {
            bookmarks = Microsoft.VisualBasic.Interaction.InputBox("Please insert your new bookmark", "New Bookmark", Urlbox.Text);
        }



        Button book1 = new Button();
        book1.Content = "Test";
        book1.Click += Button_Click;
        Bookbar.Children.Add(book1);

    }
Run Code Online (Sandbox Code Playgroud)

我正在接受

Error   1   'System.Windows.Controls.ToolBar' does not contain a definition for 'Children' and no extension method 'Children' accepting a first argument of type 'System.Windows.Controls.ToolBar' could be found (are you missing a using directive or an assembly reference?)
Run Code Online (Sandbox Code Playgroud)

在'Bookbar.Children.Add(book1);'

我究竟做错了什么?

Car*_*ine 5

它不BookBar.Children.Add()应该是BookBar.Items.Add