@@ -151,29 +151,21 @@ You can populate multilevel sub menu items in DropDown menu by using context men
151151@using Syncfusion.Blazor.SplitButtons
152152
153153<SfDropDownButton @ref="FileButton" Id="btnFileMenu" Content="File" CssClass="e-dropDown-button">
154- <ChildContent>
155- <DropDownButtonEvents OnClose="@DropDownButtonClose"></DropDownButtonEvents>
156- </ChildContent>
157154 <PopupContent>
158155 <SfContextMenu @ref="ContextMenu" Items="FileMenuItems" TValue="ContextMenuItemModel" ShowItemOnClick="true">
159156 <MenuFieldSettings Text="Content"></MenuFieldSettings>
160- <MenuEvents TValue="ContextMenuItemModel" OnClose="BeforeClose" Created="OnMenuCreated" ItemSelected="Selected" ></MenuEvents>
157+ <MenuEvents TValue="ContextMenuItemModel" OnClose="BeforeClose" Created="OnMenuCreated"></MenuEvents>
161158 </SfContextMenu>
162159 </PopupContent>
163160</SfDropDownButton>
164161
165162@code {
166163 SfDropDownButton FileButton;
167164 SfContextMenu<ContextMenuItemModel> ContextMenu;
168- public bool isClose = false;
169165
170- private void DropDownButtonClose(BeforeOpenCloseMenuEventArgs args)
171- {
172- args.Cancel = true;
173- }
174166 private void BeforeClose(BeforeOpenCloseMenuEventArgs<ContextMenuItemModel> args)
175167 {
176- if (!isClose )
168+ if (args.ParentItem == null )
177169 {
178170 FileButton.Toggle();
179171 }
@@ -187,49 +179,37 @@ You can populate multilevel sub menu items in DropDown menu by using context men
187179 public Boolean Separator { get; set; }
188180 }
189181 private List<ContextMenuItemModel> FileMenuItems = new List<ContextMenuItemModel>{
190- new ContextMenuItemModel {Id ="FileMenuItemsNew", Content = "Align" , Items = new List<ContextMenuItemModel> {
191- new ContextMenuItemModel { Content="Left" },
192- new ContextMenuItemModel { Content="Right" },
193- new ContextMenuItemModel { Content="Center" },
194- new ContextMenuItemModel { Content="Top"},
195- new ContextMenuItemModel { Content="Bottom" },
196- new ContextMenuItemModel { Content="Middle"}
197- }},
198- new ContextMenuItemModel {Id ="FileMenuItemsOpen", Content = "Open" },
199- new ContextMenuItemModel { Separator = true },
200- new ContextMenuItemModel { Id ="FileMenuItemsSave",Content = "Space", Items = new List<ContextMenuItemModel> {
201- new ContextMenuItemModel { Content="Double" },
202- new ContextMenuItemModel { Content="Single" },
203- new ContextMenuItemModel { Content="Small" },
204- new ContextMenuItemModel { Content="Big"},
205- new ContextMenuItemModel { Content="Large" },
206- }},
207- new ContextMenuItemModel { Id ="FileMenuItemsSaveAs",Content = "Save As", Items = new List<ContextMenuItemModel> {
208- new ContextMenuItemModel { Content="PDF" },
209- new ContextMenuItemModel { Content="Excel" },
210- new ContextMenuItemModel { Content="Word" },
211- new ContextMenuItemModel { Content=".XLS"},
212- } },
213- new ContextMenuItemModel {Id ="FileMenuItemsExport", Content = "Export"},
214- new ContextMenuItemModel { Separator = true},
215- new ContextMenuItemModel { Id ="FileMenuItemsPrint",Content = "Print" }
216- };
217-
218- public void OnMenuCreated()
219- {
220- ContextMenu.Open();
221- }
222-
223- public void Selected(MenuEventArgs<ContextMenuItemModel> args)
182+ new ContextMenuItemModel {Id ="FileMenuItemsNew", Content = "Align" , Items = new List<ContextMenuItemModel> {
183+ new ContextMenuItemModel { Content="Left" },
184+ new ContextMenuItemModel { Content="Right" },
185+ new ContextMenuItemModel { Content="Center" },
186+ new ContextMenuItemModel { Content="Top"},
187+ new ContextMenuItemModel { Content="Bottom" },
188+ new ContextMenuItemModel { Content="Middle"}
189+ }},
190+ new ContextMenuItemModel {Id ="FileMenuItemsOpen", Content = "Open" },
191+ new ContextMenuItemModel { Separator = true },
192+ new ContextMenuItemModel { Id ="FileMenuItemsSave",Content = "Space", Items = new List<ContextMenuItemModel> {
193+ new ContextMenuItemModel { Content="Double" },
194+ new ContextMenuItemModel { Content="Single" },
195+ new ContextMenuItemModel { Content="Small" },
196+ new ContextMenuItemModel { Content="Big"},
197+ new ContextMenuItemModel { Content="Large" },
198+ }},
199+ new ContextMenuItemModel { Id ="FileMenuItemsSaveAs",Content = "Save As", Items = new List<ContextMenuItemModel> {
200+ new ContextMenuItemModel { Content="PDF" },
201+ new ContextMenuItemModel { Content="Excel" },
202+ new ContextMenuItemModel { Content="Word" },
203+ new ContextMenuItemModel { Content=".XLS"},
204+ } },
205+ new ContextMenuItemModel {Id ="FileMenuItemsExport", Content = "Export"},
206+ new ContextMenuItemModel { Separator = true},
207+ new ContextMenuItemModel { Id ="FileMenuItemsPrint",Content = "Print" }
208+ };
209+
210+ public async Task OnMenuCreated()
224211 {
225- if (args.Item.Content == "Space" || args.Item.Content == "Save As" || args.Item.Content == "Align")
226- {
227- isClose = true;
228- }
229- else
230- {
231- isClose = false;
232- }
212+ await ContextMenu.OpenAsync();
233213 }
234214}
235215
0 commit comments