From 4a49e45647414620fe3d3efe4639043f2200e152 Mon Sep 17 00:00:00 2001 From: Nithi-22 <90109517+Nithi-22@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:51:37 +0530 Subject: [PATCH] update ToolBarAdv-state.md --- wpf/ToolBar/ToolBarAdv-state.md | 266 ++++++++++++++++++-------------- 1 file changed, 152 insertions(+), 114 deletions(-) diff --git a/wpf/ToolBar/ToolBarAdv-state.md b/wpf/ToolBar/ToolBarAdv-state.md index 1764c1066..404ea3475 100644 --- a/wpf/ToolBar/ToolBarAdv-state.md +++ b/wpf/ToolBar/ToolBarAdv-state.md @@ -14,112 +14,79 @@ ToolBarAdv provides different states such as Docking, Floating or Hidden. It can {% highlight XAML %} - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + {% endhighlight %} {% highlight C# %} - -ToolBarAdv toolBar = new ToolBarAdv(); - -toolBar.FloatingBarLocation = new Point(500, 300); - -ToolBarManager.SetToolBarState(toolBar, ToolBarState.Floating); - -Grid1.Children.Add(toolBar); - - + ToolBarManager toolBarManager = new ToolBarManager(); + //Initialize ToolBarTrayAdv + ToolBarTrayAdv toolBarTray = new ToolBarTrayAdv(); + ToolBarAdv toolbar1 = new ToolBarAdv(); + // Add a button to the toolbar1 + toolbar1.Items.Add(new Button + { + Content = new Image + { + Source = new BitmapImage(new Uri("Images/Open.png")), + Stretch = Stretch.Uniform + }, + Height = 40, + Width = 40, + ToolTip = "Open Folder", + Margin = new Thickness(5, 0, 5, 0) + }); + // Add toolbar1 to the ToolBarTrayAdv + toolBarTray.ToolBars.Add(toolbar1); + // Set Floating location for the floating toolbar + toolbar1.FloatingBarLocation = new Point(500, 300); + // Set the floating toolbar state to floating + ToolBarManager.SetToolBarState(toolbar1, ToolBarState.Floating); + // Add buttons to the floating toolbar + toolbar1.Items.Add(new Button + { + Content = new Image + { + Source = new BitmapImage(new Uri("Images/Save.png")), + Stretch = Stretch.Uniform + }, + Height = 40, + Width = 40, + ToolTip = "Save", + Margin = new Thickness(5, 0, 5, 0) + }); + // Set the ToolBarTrayAdv as the top tray for the ToolBarManager + toolBarManager.TopToolBarTray = toolBarTray; + // Set the ToolBarManager as the main content + this.Content = toolBarManager; {% endhighlight %} @@ -127,7 +94,6 @@ Grid1.Children.Add(toolBar); ![ToolBarAdv-state-img1](ToolBarAdv-state-images/ToolBarAdv-state-img1.jpeg) - ToolBarAdv can be floated only when it is hosted in ToolBarManager. ## Specifying location for floating ToolBarAdv. @@ -138,20 +104,14 @@ The location of the floating ToolBarAdv can be changed using theĀ `FloatingBarLo {% highlight XAML %} - - - + {% endhighlight %} {% highlight C# %} - -ToolBarAdv toolBar = new ToolBarAdv(); - -toolBar.FloatingBarLocation = new Point(50, 50); - - + ToolBarAdv toolBar = new ToolBarAdv(); + toolBar.FloatingBarLocation = new Point(50, 50); {% endhighlight %} @@ -172,19 +132,97 @@ Following code restricts docking at the top: {% highlight XAML %} - + +{% endhighlight %} + +{% highlight C# %} + ToolBarManager toolBarManager = new ToolBarManager(); + toolBarManager.CanDockAtTop = false; {% endhighlight %} -{% highlight C# %} +{% endtabs%} + +## ToolBarStateChanged event + +The [ToolBarStateChanged](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Tools.Controls.ToolBarAdv.html#Syncfusion_Windows_Tools_Controls_ToolBarAdv_ToolBarStateChanged) event is triggered when the state of a ToolBarAdv changes, such as when it is hidden, floated, or docked. This event passes an instance of [ToolBarStateChangedEventArgs](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Tools.Controls.ToolBarStateChangedEventArgs.html), which contains information about the state change, including the old state and the new state of the toolbar. -ToolBarManager toolBarManager = new ToolBarManager(); +NewState: Gets the current state of the ToolBarAdv control. -toolBarManager.CanDockAtTop = false; +OldState: Gets the previous state of the ToolBarAdv control. +{% tabs %} + +{% highlight XAML %} + + + + + + + + + + + + + + +{% endhighlight %} + +{% highlight C# %} + ToolBarManager toolBarManager = new ToolBarManager(); + ToolBarTrayAdv toolBarTray = new ToolBarTrayAdv(); + ToolBarAdv toolbar1 = new ToolBarAdv(); + // Subscribe to the ToolBarStateChanged event for toolbar1 + toolbar1.ToolBarStateChanged += Toolbar1_ToolBarStateChanged; + toolbar1.Items.Add(new Button + { + Content = new Image + { + Source = new BitmapImage(new Uri("Images\\Open.png")), + Stretch = Stretch.Uniform + }, + Height = 40, + Width = 40, + ToolTip = "Open Folder", + Margin = new Thickness(5, 0, 5, 0) + }); + ToolBarAdv toolbar2 = new ToolBarAdv(); + toolbar2.Items.Add(new Button + { + Content = new Image + { + Source = new BitmapImage(new Uri("Images\\Save.png")), + Stretch = Stretch.Uniform + }, + Height = 40, + Width = 40, + ToolTip = "Save", + Margin = new Thickness(5, 0, 5, 0) + }); + // Add ToolBars to the ToolBarTrayAdv + toolBarTray.ToolBars.Add(toolbar1); + toolBarTray.ToolBars.Add(toolbar2); + // Set the ToolBarTrayAdv as the top tray for the ToolBarManager + toolBarManager.TopToolBarTray = toolBarTray; + this.Content = toolBarManager; + + private void Toolbar1_ToolBarStateChanged(object sender, ToolBarStateChangedEventArgs e) + { + // Access the new and old values + object oldValue = e.OldState; + object newValue = e.NewState; + } {% endhighlight %}