locked
Accessing items from WPF Toolbar Overflow Panel RRS feed

  • Question

  • Hi ,

    Thanks for your help in previous toolbar related questions. It is related to a WPF Toolbar. I was trying to bind some button controls to Toolbar and i am having issues finding the buttons which are in overflowpanel but i can find controls withing the toolbarpanel.

    Now, while i was trying to provide the buttons within the template of Toolbar, it binds to toolbar and overflow panel correctly. And if i was trying to access the buttons within the pop up from project then those buttons are not found and i am getting object instance not set to reference... error.

    I am thinking , is there a way that i can design the entire toolbar with Srollviewer, Popup, Toggle button combined together to design a Toolbar or do you suggest some ideas on finding the buttons within the Popup window and Overflow Panel ?

     

    Thanks for your help in advance,

     

    San
    Wednesday, March 16, 2011 3:23 AM

Answers

  • There must be something else you're doing besides changing the position of the OverflowPanel for this works as it should.

    Say I did the CustomToolBar like so:

    public class CustomToolBar : ToolBar
    {
      public override void OnApplyTemplate()
      {
        base.OnApplyTemplate();
        var popup = GetTemplateChild("OverflowPopup") as Popup;
        popup.PlacementTarget = this;
        popup.Placement = PlacementMode.Bottom;
      }
    }
    

    And used it like so:

    <Window x:Class="ToolBarOverflowCustomization.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        xmlns:local="clr-namespace:ToolBarOverflowCustomization">
      <Grid>
        <local:CustomToolBar VerticalAlignment="Top" Width="100" HorizontalAlignment="Left">
          <Button Content="Button 1" Click="Button_Click"/>
          <Button Content="Button 2" Click="Button_Click"/>
          <Button Content="Button 3" Click="Button_Click"/>
          <Button Content="Button 4" Click="Button_Click"/>
          <Button Content="Button 5" Click="Button_Click"/>
        </local:CustomToolBar>
      </Grid>
    </Window>
    

    And had the handler like so:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
      MessageBox.Show("You clicked " +
        (sender as ContentControl).Content);
    }
    


    Bigsby, Lisboa, Portugal
    O que for, quando for, é que será o que é...
    Wenn ist das Nunstruck git und Slotermeyer? Ja! ... Beiherhund das Oder die Flipperwaldt gersput!
    http://bigsbyspot.wordpress.com
    • Marked as answer by StarterKit Monday, April 25, 2011 11:22 PM
    Wednesday, March 16, 2011 11:54 AM

All replies

  • Could you share some important code?
    Stay hungry, stay foolish
    Wednesday, March 16, 2011 4:47 AM
  • There must be something else you're doing besides changing the position of the OverflowPanel for this works as it should.

    Say I did the CustomToolBar like so:

    public class CustomToolBar : ToolBar
    {
      public override void OnApplyTemplate()
      {
        base.OnApplyTemplate();
        var popup = GetTemplateChild("OverflowPopup") as Popup;
        popup.PlacementTarget = this;
        popup.Placement = PlacementMode.Bottom;
      }
    }
    

    And used it like so:

    <Window x:Class="ToolBarOverflowCustomization.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        xmlns:local="clr-namespace:ToolBarOverflowCustomization">
      <Grid>
        <local:CustomToolBar VerticalAlignment="Top" Width="100" HorizontalAlignment="Left">
          <Button Content="Button 1" Click="Button_Click"/>
          <Button Content="Button 2" Click="Button_Click"/>
          <Button Content="Button 3" Click="Button_Click"/>
          <Button Content="Button 4" Click="Button_Click"/>
          <Button Content="Button 5" Click="Button_Click"/>
        </local:CustomToolBar>
      </Grid>
    </Window>
    

    And had the handler like so:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
      MessageBox.Show("You clicked " +
        (sender as ContentControl).Content);
    }
    


    Bigsby, Lisboa, Portugal
    O que for, quando for, é que será o que é...
    Wenn ist das Nunstruck git und Slotermeyer? Ja! ... Beiherhund das Oder die Flipperwaldt gersput!
    http://bigsbyspot.wordpress.com
    • Marked as answer by StarterKit Monday, April 25, 2011 11:22 PM
    Wednesday, March 16, 2011 11:54 AM
  • Hi Bigsby,

     

    I have done pretty much the same thing. In addition to that i am using the Toolbar.xaml and Shared.xaml to Style and layout my design of toolbar. So could you please suggest me whether did i went wrong any where in Toolabar.xaml when i was trying to create layout ?

    You can find the project at : http://cid-6144729088150312.office.live.com/browse.aspx/ToolBarStyling?client=wnf

    Also, i have created custom control and tried, but the same thing, so i am thinking there is a catach may be somewhere in Toolbar.xaml resource file.

    Help would be appreciated.

    Thanks,

     

    San

    Wednesday, March 16, 2011 1:53 PM
  • Hi All,

    Sorry for my jumping in.

    Hi StarterKit,

    Could you upload a zipped file?

     

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 18, 2011 4:01 AM