Search code examples
wpftoolbar

How to Change WrapWidth value of ToolBarOverflowPanel in WPF ToolBar


Need to change WrapWidth value of ToolBarOverflowPanel in ToolBar.

Tried to set value for ToolBarOverflowPanel WrapWidth using ToolBar Style.it shows error

<ToolBar Name="myToolBar" Height="50"  Band="1" ToolBarTray.IsLocked="True" >
            <ToolBar.Style>
                <Style TargetType="ToolBarOverflowPanel">
                    <Setter Property="WrapWidth" Value="20"></Setter>
                </Style>
            </ToolBar.Style>
            <Button Height="24" Width="24" Margin="4" BorderBrush="Black">

            </Button>
            <Button Height="24" Width="24"  Margin="4" BorderBrush="Black">

            </Button>
             <Grid>
                <Separator Margin="4">
                    <Separator.LayoutTransform>
                        <RotateTransform Angle="90" />
                    </Separator.LayoutTransform>
                </Separator>
            </Grid>
            <Button Height="24" Width="24" Margin="4" BorderBrush="Black">

            </Button>
            <Button Height="24" Width="24"  Margin="4" BorderBrush="Black">

            </Button>
            <Grid>
                <Separator Margin="4">
                    <Separator.LayoutTransform>
                        <RotateTransform Angle="90" />
                    </Separator.LayoutTransform>
                </Separator>
            </Grid>


            <Button Height="24" Width="24" Margin="4" BorderBrush="Black">

            </Button>
            <Button Height="24" Width="24"  Margin="4" BorderBrush="Black">


        </ToolBar>

Need to change wrapwidth value without changing toolbar template.


Solution

  • The thing is that toolbar is using another controls in its template. If you want to override the default style/behavior then you need to look at here.