2013-12-16 66 views
1

我試圖向我的瀏覽器添加書籤功能,但我無法弄清楚如何將創建的按鈕添加到工具欄。在XAML定義以編程方式在wpf中將按鈕添加到工具欄

我的工具欄:

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

     </ToolBar> 

和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); 

    } 

我recieving

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?) 
'Bookbar.Children.Add(book1)'上的'

';'

我在做什麼錯?

+0

什麼錯誤,你接受? – franssu

+0

哦,我很抱歉,把它添加到主帖子中。 – manske

回答

4

它不是BookBar.Children.Add()應該BookBar.Items.Add

+0

它就像一個魅力!謝謝! – manske

相關問題