The declarative syntax
makes it very easy to apply styles per menu level. The LevelMenuItemStyles object is also available
at runtime and can be altered as shown in the StyleCollectionDemo web form Page_Load
event handler:
CHAPTER 4 ?– THE WEBCONTROL BASE C LASS AND CONTROL STYLES 179
MenuItemStyle alterStyle = new MenuItemStyle();
alterStyle.BackColor = System.Drawing.Color.Navy;
alterStyle.ForeColor = System.Drawing.Color.Gold;
// Remove the last of the three menu item styles. Note that
// since the collection has a zero-based index, the third
// entry has an index value of 2.
MainMenuID.LevelMenuItemStyles.RemoveAt(2);
MainMenuID.LevelMenuItemStyles.Add(alterStyle);
Figure 4-19 shows the StyleMenuCollectionDemo web form.
Figure 4-19. StyleCollectionDemo web form in Action
In Figure 4-19, you can see the styles applied to the three menu levels, including the dynamically
altered style for the third menu level, providing a highly intuitive means to apply styles.
Listings 4-13 and 4-14 show the code for the StyleCollectionDemo web form.
Listing 4-13. The StyleCollectionDemo Web Form .aspx File
<%@ Page Language="C#"
MasterPageFile="~/MasterPage/ControlsBook2MasterPage.Master"
AutoEventWireup="true" CodeBehind="StyleCollectionDemo.
Pages:
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273