locked
Simple question: where is the standard Windows default button xaml markup? RRS feed

  • Question

  • I seem to have, in a certain part of my xaml file, temporarily lost the ability to add a standard grey with rounded edges Windows default button.

    Can anybody post the XAML for this button, so I can cut and paste it?  If there's a better way of making the button reappear please let me know.  The button does appear in other parts of my project, so it's in the library somewhere.

    RC
    Monday, November 16, 2009 9:17 PM

Answers

  • Hi, I'm not sure if this is what you're asking for, but I took a copy of the default button's style template:

    	<UserControl.Resources>
    		<Style x:Key="ButtonFocusVisual">
    			<Setter Property="Control.Template">
    				<Setter.Value>
    					<ControlTemplate>
    						<Rectangle Stroke="Black" StrokeDashArray="1 2" StrokeThickness="1" Margin="3" SnapsToDevicePixels="true"/>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    		<LinearGradientBrush x:Key="ButtonNormalBackgroundFill" EndPoint="0.5,1" StartPoint="0.5,0">
    			<GradientStop Color="#FFFFFFFF" Offset="0"/>
    			<GradientStop Color="#FFF0F0EA" Offset="0.9"/>
    		</LinearGradientBrush>
    		<SolidColorBrush x:Key="ButtonBorder" Color="#FF003C74"/>
    		<Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
    			<Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
    			<Setter Property="Background" Value="{StaticResource ButtonNormalBackgroundFill}"/>
    			<Setter Property="BorderBrush" Value="{StaticResource ButtonBorder}"/>
    			<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    			<Setter Property="HorizontalContentAlignment" Value="Center"/>
    			<Setter Property="VerticalContentAlignment" Value="Center"/>
    			<Setter Property="Template">
    				<Setter.Value>
    					<ControlTemplate TargetType="{x:Type Button}">
    						<Microsoft_Windows_Themes:ButtonChrome x:Name="Chrome" SnapsToDevicePixels="true" BorderBrush="{TemplateBinding BorderBrush}" Fill="{TemplateBinding Background}" RenderDefaulted="{TemplateBinding IsDefaulted}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" ThemeColor="NormalColor">
    							<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" RecognizesAccessKey="True"/>
    						</Microsoft_Windows_Themes:ButtonChrome>
    						<ControlTemplate.Triggers>
    							<Trigger Property="IsKeyboardFocused" Value="true">
    								<Setter Property="RenderDefaulted" TargetName="Chrome" Value="true"/>
    							</Trigger>
    							<Trigger Property="ToggleButton.IsChecked" Value="true">
    								<Setter Property="RenderPressed" TargetName="Chrome" Value="true"/>
    							</Trigger>
    							<Trigger Property="IsEnabled" Value="false">
    								<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
    							</Trigger>
    						</ControlTemplate.Triggers>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    	</UserControl.Resources>
    • Proposed as answer by DaveyBoy1138 Wednesday, November 18, 2009 1:21 AM
    • Marked as answer by RonConger09 Wednesday, November 18, 2009 11:30 PM
    Wednesday, November 18, 2009 1:20 AM
  • In Expresion Blend, in left of panel is an pannel con Objects elements. Your Button is write it in panel. Click Right at this Button and choise a modify copy of button. In user control is write User resurces with this button Style. The Button are un references with Style1. That style you can modify. In Right panel in resources is show the usercontrol and new resurces Button style. If you want to modify. choise modify and in left panel is writen "style" Click Right and choise modify current and select the states panel. This state is default don't can delet it bat can create the new rectangle and state, and you can delete the old rectangle. Good luck!
    • Marked as answer by RonConger09 Thursday, November 19, 2009 8:35 PM
    Thursday, November 19, 2009 6:27 PM

All replies

  • Hi, I'm not sure if this is what you're asking for, but I took a copy of the default button's style template:

    	<UserControl.Resources>
    		<Style x:Key="ButtonFocusVisual">
    			<Setter Property="Control.Template">
    				<Setter.Value>
    					<ControlTemplate>
    						<Rectangle Stroke="Black" StrokeDashArray="1 2" StrokeThickness="1" Margin="3" SnapsToDevicePixels="true"/>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    		<LinearGradientBrush x:Key="ButtonNormalBackgroundFill" EndPoint="0.5,1" StartPoint="0.5,0">
    			<GradientStop Color="#FFFFFFFF" Offset="0"/>
    			<GradientStop Color="#FFF0F0EA" Offset="0.9"/>
    		</LinearGradientBrush>
    		<SolidColorBrush x:Key="ButtonBorder" Color="#FF003C74"/>
    		<Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
    			<Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
    			<Setter Property="Background" Value="{StaticResource ButtonNormalBackgroundFill}"/>
    			<Setter Property="BorderBrush" Value="{StaticResource ButtonBorder}"/>
    			<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    			<Setter Property="HorizontalContentAlignment" Value="Center"/>
    			<Setter Property="VerticalContentAlignment" Value="Center"/>
    			<Setter Property="Template">
    				<Setter.Value>
    					<ControlTemplate TargetType="{x:Type Button}">
    						<Microsoft_Windows_Themes:ButtonChrome x:Name="Chrome" SnapsToDevicePixels="true" BorderBrush="{TemplateBinding BorderBrush}" Fill="{TemplateBinding Background}" RenderDefaulted="{TemplateBinding IsDefaulted}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" ThemeColor="NormalColor">
    							<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" RecognizesAccessKey="True"/>
    						</Microsoft_Windows_Themes:ButtonChrome>
    						<ControlTemplate.Triggers>
    							<Trigger Property="IsKeyboardFocused" Value="true">
    								<Setter Property="RenderDefaulted" TargetName="Chrome" Value="true"/>
    							</Trigger>
    							<Trigger Property="ToggleButton.IsChecked" Value="true">
    								<Setter Property="RenderPressed" TargetName="Chrome" Value="true"/>
    							</Trigger>
    							<Trigger Property="IsEnabled" Value="false">
    								<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
    							</Trigger>
    						</ControlTemplate.Triggers>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    	</UserControl.Resources>
    • Proposed as answer by DaveyBoy1138 Wednesday, November 18, 2009 1:21 AM
    • Marked as answer by RonConger09 Wednesday, November 18, 2009 11:30 PM
    Wednesday, November 18, 2009 1:20 AM
  • Thanks anyway, but I could not get this to compile.  I tried placing it in various places but it got the usual 'missing assembly reference' and such errors.

    But this is not a big deal so I thank you for your time and I will mark as an answer.

    BTW, if you have any links to cool examples of templates for controls, please do cite them here.
    Wednesday, November 18, 2009 11:29 PM
  • Hi, please don't mark this as an answer if it didn't work for you.  Perhaps I can get you to where you need to be, however.

    The XAML I posted above was only for the standard button style.  You can't just copy and paste it over the existing XAML in your project because it doesn't stand alone.  You need to set the button style to "ButtonStyle1" wherever you have a Button element in your XAML.  I think that will give you what you want, although it's a bit tedious because you should just get this automatically, by default.  Is there anything in App.xaml that's causing your default button style to get overridden somehow?
    Thursday, November 19, 2009 12:02 AM
  • In Expresion Blend, in left of panel is an pannel con Objects elements. Your Button is write it in panel. Click Right at this Button and choise a modify copy of button. In user control is write User resurces with this button Style. The Button are un references with Style1. That style you can modify. In Right panel in resources is show the usercontrol and new resurces Button style. If you want to modify. choise modify and in left panel is writen "style" Click Right and choise modify current and select the states panel. This state is default don't can delet it bat can create the new rectangle and state, and you can delete the old rectangle. Good luck!
    • Marked as answer by RonConger09 Thursday, November 19, 2009 8:35 PM
    Thursday, November 19, 2009 6:27 PM
  • Somehow the button came back!  I played around with the control it was wrapped in, and voila it appeared.  I am hand coding using XAML--I cannot get Blend2 to work with code :-(  But maybe I'll upgrade to Blend3 and get it to work.  Blend 2 is nice though for ideas on how to do stuff, but I cannot get it to work seamlessly with Visual Studio 2008.
    Thursday, November 19, 2009 8:36 PM