WPF ToolBar: How to arrange toolbars at design-time - wpf

I've got two Wpf ToolBars in a single ToolBarTray. How to make them fit on two rows?
I noticed users can move them at run-time. Is there a way to get the same behavior at design-time without using two ToolBarTrays ?
To sumarize, at startup, I want this:
instead of that:
Thanks

Use Band and BandIndex to control toolbar layout.
<ToolBarTray Background="White">
<ToolBar Band="1" BandIndex="1">
<Button Content="B1"/>
<Button Content="B2"/>
<Button Content="B3"/>
</ToolBar>
<ToolBar Band="2" BandIndex="1">
<Button Content="B4"/>
<Button Content="B5"/>
</ToolBar>
<ToolBar Band="2" BandIndex="2">
<Button Content="B6"/>
<Button Content="B7"/>
</ToolBar>
</ToolBarTray>

Related

WPF Tabs Stack button

I have 5 buttons stacked as below, with each button corresponding to a grid containing datagrid. Now I click on the 2nd button below, I want the second button to move up grid.row="1" with its grid part to move up Grid.Row="2" and its Grid.SpanRow = "5" (the first button remains in place but its grid will disapear) and it must have an up animation. but I can't know how to do this and how to hide grids when another grid is showing. Anyone have any other ideas for me? Sorry for my bad discription cuz i just started coding with wpf 2 weaks ago. Thanks all guys first.
This is my code:
<Border>
<Grid>
<Grid.RowDefinitions>
...*11Rows (I dont know why this isn't shown, Grid.RowDefinitions)
</Grid.RowDefinitions>
<Button > Phương tiện</Button>
<Button Grid.Row="7" Name="btn1"> Điểm đánh dấu
</Button>
<Button Grid.Row="8">Cây tốc độ</Button>
<Button Grid.Row="9">Tìm kiếm nhanh</Button>
<Button Grid.Row="10">Mô phỏng lịch sử</Button>
<Button Grid.Row="11">Điểm đánh dấu</Button>
<Grid Grid.Row="1" Grid.RowSpan="6" x:Name="gr1"> blabla </Grid>
</Grid>
</Border>
[2

A value of type toolbar cannot be added to a collection or dictionary of type Collection

I get the error described in the title using Toolbar(s) in a ToolBarTray like the following:
<ToolBarTray DockPanel.Dock="Top">
<ToolBar>
<Button Command="New" Content="New" />
<Button Command="Open" Content="Open" />
<Button Command="Save" Content="Save" />
</ToolBar>
<ToolBar>
<Button Command="Cut" Content="Cut" />
<Button Command="Copy" Content="Copy" />
<Button Command="Paste" Content="Paste" />
</ToolBar>
</ToolBarTray>
I can compile the program, it works perfectly, but I continue to get the error in Visual Studio.
Looks like I'm missing something, but I have no clue of what it is...
Any idea? Thanks in advance!
Edit Problem magically disappeared. The only thing I can say is that this morning I did a reboot (I'm not sure if I did reboots while having the error: I often hybernate my machine).

What is the exact difference between ToolBarPanel and ToolBarTray in wpf?

What is the exact difference between ToolBarPanel and ToolBarTray in WPF?
Here you are
The ToolBar uses a ToolBarPanel and a ToolBarOverflowPanel in its ControlTemplate. The ToolBarPanel is responsible for the layout of the items on the toolbar. The ToolBarOverflowPanel is responsible for the layout of the items that do not fit on the ToolBar. For an example of a ControlTemplate for a ToolBar, see
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/controls/toolbar-overview?view=netframeworkdesktop-4.8
ToolBarPanel Class
XAML
<ToolBarTray Background="White">
<ToolBar Band="1" BandIndex="1">
<Button>
<Image Source="toolbargraphics\cut.bmp" />
</Button>
<Button>
<Image Source="toolbargraphics\copy.bmp" />
</Button>
<Button>
<Image Source="toolbargraphics\paste.bmp" />
</Button>
<Button>
<Image Source="toolbargraphics\undo.bmp" />
</Button>
<Button>
<Image Source="toolbargraphics\redo.bmp" />
</Button>
<Button>
<Image Source="toolbargraphics\paint.bmp" />
</Button>
<Button>
<Image Source="toolbargraphics\spell.bmp" />
</Button>
<Separator/>
<Button ToolBar.OverflowMode="Always">
<Image Source="toolbargraphics\save.bmp" />
</Button>
<Button ToolBar.OverflowMode="Always">
<Image Source="toolbargraphics\open.bmp" />
</Button>
<Button ToolBar.OverflowMode="Always">
<Image Source="toolbargraphics\print.bmp" />
</Button>
<Button ToolBar.OverflowMode="Always">
<Image Source="toolbargraphics\preview.bmp" />
</Button>
</ToolBar>
</ToolBarTray>

How to make a WPF TextBox fill all available space between two buttons ?

I'm trying to make a WPF TextBox fill all available space between two buttons. For some reason the code below does not what I'm trying to achieve
<DockPanel Height="48" LastChildFill="False">
<Button DockPanel.Dock="Left">
<Image Source="Images\large_load.png"></Image>
</Button>
<Button DockPanel.Dock="Left">
<Image Source="Images\large_reload.png"></Image>
</Button>
<TextBox Height="24" HorizontalAlignment="Stretch" DockPanel.Dock="Left"></TextBox>
<Button DockPanel.Dock="Right" Width="48">
<Image Source="Images\large_delete.png"></Image>
</Button>
</DockPanel>
The TextBox is not stretched.
Another problem is that when text is added, the textbox width increases and eventually it pushes the right button out of the visible space.
Don't set LastChildFill to false and make the TextBox the last child (by moving the element to the bottom in the code).
(Or use a proper control, like a Grid)

Align button content

I want the content of a wpf button to be left aligned
I tried the following but the text is still centered inside the button.
<Button >
<StackPanel HorizontalAlignment="Stretch">
<TextBlock HorizontalAlignment="Left" Text="Save"/>
</StackPanel>
</Button>
What do i do?
Found it, it's HorizontalContentAlignment.
:)
You don't need the StackPanel or the TextBlock. All you need is
<Button HorizontalContentAlignment="Left" Content="Save" />
You can align in two way, Horizontal and Vertical
<Button Content="Export" VerticalContentAlignment="Bottom" name="MyBtn1" />
or
<Button Content="Export" HorizontalContentAlignment="Center" name="MyBtn2" />
See the follow image to view the possibilities settings:

Resources