Home > Sample chapters > Programming > Visual Basic

Microsoft Visual Basic 2013 Step by Step: Using XAML Styles

IDE shortcuts for applying styles

A useful shortcut for applying XAML styles like the ones that you have created in this chapter is to right-click an object on the page that you want to format with a new style and apply the style name from a list in a pop-up window. When you apply XAML styles in this way, using only commands in the IDE, Visual Studio updates the XAML markup for you automatically. You won’t need to manually enter the style using the XAML Style property in the Code Editor.

Give this shortcut a try now.

Apply a XAML style using the IDE

  1. In the Designer, right-click the first button on the page.

  2. In the pop-up menu that appears, click Edit Template | Apply Resource | YellowGradient.

  3. Your screen will look this as you are making your style resource selection:

    The two styles that you added to the App.xaml file (GradientButton and YellowGradient) are now ready for you to use at the click of a button.

    After you select the YellowGradient style, Visual Studio applies it to the object selected in the Designer and updates the Style property for the object in the XAML markup and Code Editor.

    That’s all there is to it! You’ve learned another useful way to take advantage of style resources in a Visual Studio project!

  4. Save your changes, and exit Visual Studio.

You’re finished working with XAML styles in this chapter. Be sure to use them as you design Windows Store apps, and return to this chapter for a refresher course when you start building larger projects—styles become incredibly useful in larger, team-development efforts.