Hi,@vitaminchik. Welcome Microsoft Q&A. You could refer to the following code. MainWindow.xaml:
<StackPanel x:Name="sp">
<Frame x:Name="myFrame" Width="450" Height="200"/>
</StackPanel>
MainWindow.xaml.cs:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Page1 page1 = new Page1();
myFrame.Navigate(page1);
}
}
Page1.xaml:
<Grid Background="AliceBlue" Name="grid">
</Grid>
Page1.xaml.cs:
public partial class Page1 : Page
{
public Page1()
{
InitializeComponent();
grid.Children.Add( CreatetoolBarTray());
}
public ToolBarTray CreatetoolBarTray()
{
var tbt = new ToolBarTray
{
Width = 450.0,
IsLocked = true
};
var tb = new ToolBar();
var b = new Binding
{
Path = new PropertyPath("ActualWidth"),
Source = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(ToolBarTray), 1),
};
tb.SetBinding(WidthProperty, b);
tb.Items.Add(new Button() { Content = "b1" , Width=50,Background=Brushes.LightGray});
tb.Items.Add(new Button() { Content = "b2" ,Width = 50, Background = Brushes.LightGray });
tbt.ToolBars.Add(tb);
return tbt;
}
}
The result:
If the response is helpful, please click "Accept Answer" and upvote it. Note: Please follow the steps in our [documentation][5] to enable e-mail notifications if you want to receive the related email notification for this thread. [5]: https://docs.microsoft.com/en-us/answers/articles/67444/email-notifications.html