WPF Toolbar Items HorizontalAligment=“Right”

后端 未结 8 1712
说谎
说谎 2020-12-10 12:41

Is it possible to make the elements within a WPF toolbar have a HorizontalAlignment of Right?



        
相关标签:
8条回答
  • 2020-12-10 13:08
        <ToolBar Width="100" VerticalAlignment="Top" >
            <ToolBar.Resources>
                <Style TargetType="{x:Type ToolBarPanel}">
                    <Setter Property="Orientation" Value="Vertical"/>
                </Style>
            </ToolBar.Resources>
    
            <DockPanel>
                <ToolBarPanel Orientation="Horizontal" >
                    <Button>A</Button>
                    <Button>B</Button>
                </ToolBarPanel>
                <Button DockPanel.Dock="Right" HorizontalAlignment="Right">C</Button>
            </DockPanel>
        </ToolBar>
    

    0 讨论(0)
  • 2020-12-10 13:12

    I'm not very satisfied with the "WidthConverter" solution because I got some dynamic elements at end. Further search led me to here, which seems to be working perfect for me. Here is my code sample in case you are interested:

    <ToolBar Name="toolBar">
        <DockPanel Width="{Binding Path=ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type ToolBarPanel}}}">
            <DockPanel.Resources>
                <Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"></Style>
            </DockPanel.Resources>
            <Button x:Name="btnRefresh" ToolTip="Refresh" Click="btnRefresh_Click">
                <Image Margin="2 0" Source="/Resources/refresh.ico" Height="16" Width="16"/>
            </Button>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                <Image Margin="2 0" Source="/Resources/Help.ico" Height="16" Width="16"/>
                <TextBlock Text="Help" Margin="2 0" VerticalAlignment="Center"/>
            </StackPanel>
        </DockPanel>
    </ToolBar>
    
    0 讨论(0)
提交回复
热议问题