locked
Can I specify a default button style for only one xaml page? RRS feed

  • Question

  • I'd like to specify a default style for buttons in one Xaml page, is this possible?  I have my button style in a resource dictionary (rdButtons.xaml) and then I have a variety of buttons in a user control that will appear in a portion of the main window. I'd like to apply a single default style en masse, if possible, to those buttons.

    Thank you for any assistance.


    Purkiss

    Tuesday, February 7, 2012 9:04 PM

All replies

  • Yes, assuming your style has a key (in my case, ButtonStyle1), like this:

    <UserControl
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	x:Class="SilverlightApplication29.MainPage"
    	Width="640" Height="480">
    	<UserControl.Resources>
    		<Style TargetType="Button" BasedOn="{StaticResource ButtonStyle1}"/>
    	</UserControl.Resources>
    
    	<Grid x:Name="LayoutRoot" Background="White">
    		<Button Content="Button" HorizontalAlignment="Left" Margin="80,207,0,153" Width="131" />
    		<Button Content="Button" HorizontalAlignment="Right" Height="107" Margin="0,103,161,0" VerticalAlignment="Top" Width="148"/>
    		<Button Content="Button" HorizontalAlignment="Right" Height="106" Margin="0,0,161,74" VerticalAlignment="Bottom" Width="82"/>
    	</Grid>
    </UserControl>

    Tuesday, February 7, 2012 10:26 PM
    Moderator