Beruflich Dokumente
Kultur Dokumente
A button that uses a custom control template and has the mouse pointer over it
This topic contains the following sections. Prerequisites When You Should Create a ControlTemplate Changing the Visual Structure of a Control Changing the Appearance of a Control Depending on Its State Specifying the Behavior of a Control When It Transitions Between States Customizing Other Controls by Understanding the Control Contract Complete Example Related Topics
Prerequisites
This topic assumes that you understand how to create and use controls and styles as discussed in Controls. The concepts discussed in this topic apply to elements that inherit from the Control class, except for the UserControl. You cannot apply a ControlTemplate to a UserControl.
12/19/13
example, you can set the Foreground property to blue and FontStyle to italic on a CheckBox.
Without the ability to create a new ControlTemplate for controls, all controls in every WPF-based application would have the same general appearance, which would limit the ability to create an application with a custom look and feel. By default, every CheckBox has similar characteristics. For example, the content of the CheckBox is always to the right of the selection indicator, and the check mark is always used to indicate that the CheckBox is selected. You create a ControlTemplate when you want to customize the control's appearance beyond what setting the other properties on the control will do. In the example of the CheckBox, suppose that you want the content of the check box to be above the selection indicator and you want an X to indicate that the CheckBox is selected. You specify these changes in the ControlTemplate of the CheckBox. The following illustration shows a CheckBox that uses a default ControlTemplate. A CheckBox that uses the default control template
The following illustration shows a CheckBox that uses a custom ControlTemplate to place the content of the CheckBox above the selection indicator and displays an X when the CheckBox is selected. A CheckBox that uses a custom control template
The ControlTemplate for the CheckBox in this sample is relatively complex, so this topic uses a simpler example of creating a ControlTemplate for a Button.
2/18
12/19/13
c o n t r o lt e m p l a t e . > < B o r d e r . B a c k g r o u n d > < S o l i d C o l o r B r u s hx : N a m e = " B o r d e r B r u s h "C o l o r = " B l a c k " / > < / B o r d e r . B a c k g r o u n d > < ! C r e a t eab o r d e rt h a th a sad i f f e r e n tc o l o r b ya d d i n gs m a l l e rg r i d .T h eb a c k g r o u n do f t h i sg r i di ss p e c i f i c i e db yt h eb u t t o n ' s B a c k g r o u n dp r o p e r t y . > < G r i dM a r g i n = " 4 "B a c k g r o u n d = " { T e m p l a t e B i n d i n gB a c k g r o u n d } " > < ! U s eaC o n t e n t P r e s e n t e rt od i s p l a yt h eC o n t e n to f t h eB u t t o n . > < C o n t e n t P r e s e n t e r H o r i z o n t a l A l i g n m e n t = " { T e m p l a t e B i n d i n gH o r i z o n t a l C o n t e n t A l i g n m e n t } " V e r t i c a l A l i g n m e n t = " { T e m p l a t e B i n d i n gV e r t i c a l C o n t e n t A l i g n m e n t } " M a r g i n = " 4 , 5 , 4 , 4 "/ > < / G r i d > < / B o r d e r > < / C o n t r o l T e m p l a t e >
12/19/13
Control.HorizontalContentAlignment can be bound to FrameworkElement.HorizontalAlignment. When you template bind a property, be sure that the target and source properties are the same type. The Control class defines several properties that must be used by the control template to have an effect on the control when they are set. How the ControlTemplate uses the property depends on the property. The ControlTemplate must use the property in one of the following ways: An element in the ControlTemplate template binds to the property. An element in the ControlTemplate inherits the property from a parent FrameworkElement. The following table lists the visual properties inherited by a control from the Control class. It also indicates whether the default control template of a control uses the inherited property value or if it must be template bound. Property Background BorderThickness BorderBrush FontFamily FontSize FontStretch FontWeight Foreground HorizontalContentAlignment Padding VerticalContentAlignment Usage method Template binding Template binding Template binding Property inheritance or template binding Property inheritance or template binding Property inheritance or template binding Property inheritance or template binding Property inheritance or template binding Template binding Template binding Template binding
The table lists only the visual properties inherited from the Control class. Apart from the properties listed in the table, a control may also inherit the DataContext, Language, and TextDecorations properties from the parent framework element. Also, if the ContentPresenter is in the ControlTemplate of a ContentControl, the ContentPresenter will automatically bind to the ContentTemplate and Content properties. Likewise, an ItemsPresenter that is in the ControlTemplate of an ItemsControl will automatically bind to the Items and ItemsPresenter properties. The following example creates two buttons that use the ControlTemplate defined in the preceding example. The example sets the Background, Foreground, and FontSize properties on each button. Setting the Background property has an effect because it is template bound in the ControlTemplate. Even though the Foreground and FontSize properties are not template bound, setting them has an effect because their values are inherited. XAML < S t a c k P a n e l > < B u t t o n S t y l e = " { S t a t i c R e s o u r c en e w T e m p l a t e } " msdn.microsoft.com/en-us/library/ee230084(d=printer,v=vs.110).aspx
4/18
12/19/13
< B u t t o nS t y l e = " { S t a t i c R e s o u r c en e w T e m p l a t e } " B a c k g r o u n d = " N a v y "F o r e g r o u n d = " W h i t e "F o n t S i z e = " 1 4 " C o n t e n t = " B u t t o n 1 " / > < B u t t o nS t y l e = " { S t a t i c R e s o u r c en e w T e m p l a t e } " B a c k g r o u n d = " P u r p l e "F o r e g r o u n d = " W h i t e "F o n t S i z e = " 1 4 " C o n t e n t = " B u t t o n 2 "H o r i z o n t a l C o n t e n t A l i g n m e n t = " L e f t " / > < / S t a c k P a n e l > The preceding example produces output that is similar to the following illustration. Two buttons with different background colors
12/19/13
The control is responsible for defining the states as part of its control contract, which is discussed in detail in Customizing Other Controls by Understanding the Control Contract later in this topic. The following table lists the states that are specified for the Button. VisualState Name Normal MouseOver Pressed Disabled Focused Unfocused VisualStateGroup Name CommonStates CommonStates CommonStates CommonStates FocusStates FocusStates Description The default state. The mouse pointer is positioned over the control. The control is pressed. The control is disabled. The control has focus. The control does not have focus.
The Button defines two state groups: the C o m m o n S t a t e sgroup contains the N o r m a l ,M o u s e O v e r ,P r e s s e d , and D i s a b l e d states. The F o c u s S t a t e sgroup contains the F o c u s e dand U n f o c u s e dstates. States in the same state group are mutually exclusive. The control is always in exactly one state per group. For example, a Button can have focus even when the mouse pointer is not over it, so a Button in the F o c u s e dstate can be in the M o u s e O v e r ,P r e s s e d , or N o r m a lstate. You add VisualState objects to VisualStateGroup objects. You add VisualStateGroup objects to the VisualStateManager.VisualStateGroups attached property. The following example defines the VisualState objects for the N o r m a l ,M o u s e O v e r , and P r e s s e dstates, which are all in the C o m m o n S t a t e sgroup. The Name of each VisualState matches the name in the preceding table. The D i s a b l e dstate and the states in the F o c u s S t a t e sgroup are omitted to keep the example short, but they are included in the entire example at the end of this topic. Note Be sure to set the VisualStateManager.VisualStateGroups attached property on the root FrameworkElement of the ControlTemplate. XAML < C o n t r o l T e m p l a t eT a r g e t T y p e = " B u t t o n " > < B o r d e rN a m e = " R o o t E l e m e n t " > < V i s u a l S t a t e M a n a g e r . V i s u a l S t a t e G r o u p s > < ! D e f i n et h es t a t e sa n dt r a n s i t i o n sf o rt h ec o m m o ns t a t e s . T h es t a t e si nt h eV i s u a l S t a t e G r o u pa r em u t u a l l ye x c l u s i v et o e a c ho t h e r . > < V i s u a l S t a t e G r o u pN a m e = " C o m m o n S t a t e s " > < ! T h eN o r m a ls t a t ei st h es t a t et h eb u t t o ni si n w h e ni ti sn o ti na n o t h e rs t a t ef r o mt h i sV i s u a l S t a t e G r o u p . > < V i s u a l S t a t eN a m e = " N o r m a l "/ > < ! C h a n g et h eS o l i d C o l o r B r u s h ,B o r d e r B r u s h ,t or e dw h e nt h e m o u s ei so v e rt h eb u t t o n . > < V i s u a l S t a t eN a m e = " M o u s e O v e r " > < S t o r y b o a r d > < C o l o r A n i m a t i o nS t o r y b o a r d . T a r g e t N a m e = " B o r d e r B r u s h " S t o r y b o a r d . T a r g e t P r o p e r t y = " C o l o r " T o = " R e d "/ >
msdn.microsoft.com/en-us/library/ee230084(d=printer,v=vs.110).aspx
6/18
12/19/13
< / S t o r y b o a r d > < / V i s u a l S t a t e > < ! C h a n g et h eS o l i d C o l o r B r u s h ,B o r d e r B r u s h ,t oT r a n s p a r e n tw h e nt h e b u t t o ni sp r e s s e d . > < V i s u a l S t a t eN a m e = " P r e s s e d " > < S t o r y b o a r d > < C o l o r A n i m a t i o nS t o r y b o a r d . T a r g e t N a m e = " B o r d e r B r u s h " S t o r y b o a r d . T a r g e t P r o p e r t y = " C o l o r " T o = " T r a n s p a r e n t " / > < / S t o r y b o a r d > < / V i s u a l S t a t e > < ! T h eD i s a b l e ds t a t ei so m i t t e df o rb r e v i t y . > < / V i s u a l S t a t e G r o u p > < / V i s u a l S t a t e M a n a g e r . V i s u a l S t a t e G r o u p s > < B o r d e r . B a c k g r o u n d > < S o l i d C o l o r B r u s hx : N a m e = " B o r d e r B r u s h "C o l o r = " B l a c k " / > < / B o r d e r . B a c k g r o u n d > < G r i dB a c k g r o u n d = " { T e m p l a t e B i n d i n gB a c k g r o u n d } "M a r g i n = " 4 " > < C o n t e n t P r e s e n t e r H o r i z o n t a l A l i g n m e n t = " { T e m p l a t e B i n d i n gH o r i z o n t a l C o n t e n t A l i g n m e n t } " V e r t i c a l A l i g n m e n t = " { T e m p l a t e B i n d i n gV e r t i c a l C o n t e n t A l i g n m e n t } " M a r g i n = " 4 , 5 , 4 , 4 "/ > < / G r i d > < / B o r d e r > < / C o n t r o l T e m p l a t e > The preceding example produces output that is similar to the following illustrations. A button that uses a custom control template in the normal state
A button that uses a custom control template in the mouse over state
To find the visual states for controls that are included with WPF, see Control Styles and Templates.
12/19/13
You can specify the amount of time that it takes an animation to occur to smoothly transition a control from one state to another by adding VisualTransition objects to the ControlTemplate. When you create a VisualTransition, you specify one or more of the following: The time it takes for a transition between states to occur. Additional changes in the control's appearance that occur at the time of the transition. Which states the VisualTransition is applied to.
msdn.microsoft.com/en-us/library/ee230084(d=printer,v=vs.110).aspx
8/18
12/19/13
You can have multiple VisualTransition objects in a VisualStateGroup that refer to the same state, but they will be used in the order that the previous table specifies. In the following example, there are two VisualTransition objects. When the control transitions from the P r e s s e dstate to the M o u s e O v e rstate, the VisualTransition that has both From and To set is used. When the control transitions from a state that is not P r e s s e dto the M o u s e O v e rstate, the other state is used. XAML < ! T a k eo n eh a l fs e c o n dt ot r a s i t i o nt ot h eM o u s e O v e rs t a t e . > < V i s u a l T r a n s i t i o nT o = " M o u s e O v e r " G e n e r a t e d D u r a t i o n = " 0 : 0 : 0 . 5 "/ > < ! T a k eo n eh u n d r e d t ho fas e c o n dt ot r a n s i t i o nf r o mt h e P r e s s e ds t a t et ot h eM o u s e O v e rs t a t e . > < V i s u a l T r a n s i t i o nF r o m = " P r e s s e d "T o = " M o u s e O v e r " G e n e r a t e d D u r a t i o n = " 0 : 0 : 0 . 0 1 "/ > The VisualStateGroup has a Transitions property that contains the VisualTransition objects that apply to the VisualState objects in the VisualStateGroup. As the ControlTemplate author, you are free to include any VisualTransition you want. However, if the To and From properties are set to state names that are not in the VisualStateGroup, the VisualTransition is ignored. The following example shows the VisualStateGroup for the C o m m o n S t a t e s . The example defines a VisualTransition for each of the button's following transitions. To the P r e s s e dstate.
msdn.microsoft.com/en-us/library/ee230084(d=printer,v=vs.110).aspx 9/18
12/19/13
To the P r e s s e dstate.
To the M o u s e O v e rstate. From the P r e s s e dstate to the M o u s e O v e rstate. From the M o u s e O v e rstate to the N o r m a lstate.
XAML < V i s u a l S t a t e G r o u pN a m e = " C o m m o n S t a t e s " > < ! D e f i n et h eV i s u a l T r a n s i t i o n st h a t c a nb eu s e dw h e nt h ec o n t r o lt r a n s i t i o n s b e t w e e nV i s u a l S t a t e st h a ta r ed e f i n e di nt h e V i s u a l S t a t G r o u p . > < V i s u a l S t a t e G r o u p . T r a n s i t i o n s > < ! T a k eo n eh u n d r e d t ho fas e c o n dt o t r a n s i t i o nt ot h eP r e s s e ds t a t e . > < V i s u a l T r a n s i t i o nT o = " P r e s s e d " G e n e r a t e d D u r a t i o n = " 0 : 0 : 0 . 0 1 "/ > < ! T a k eo n eh a l fs e c o n dt ot r a s i t i o n t ot h eM o u s e O v e rs t a t e . > < V i s u a l T r a n s i t i o nT o = " M o u s e O v e r " G e n e r a t e d D u r a t i o n = " 0 : 0 : 0 . 5 "/ > < ! T a k eo n eh u n d r e d t ho fas e c o n dt ot r a n s i t i o nf r o mt h e P r e s s e ds t a t et ot h eM o u s e O v e rs t a t e . > < V i s u a l T r a n s i t i o nF r o m = " P r e s s e d "T o = " M o u s e O v e r " G e n e r a t e d D u r a t i o n = " 0 : 0 : 0 . 0 1 "/ > < ! T a k eo n ea n dah a l fs e c o n d st ot r a n s i t i o nf r o mt h e M o u s e O v e rs t a t et ot h eN o r m a ls t a t e . H a v et h eS o l i d C o l o r B r u s h ,B o r d e r B r u s h ,f a d et ob l u e , t h e nt oy e l l o w ,a n dt h e nt ob l a c ki nt h a tt i m e . > < V i s u a l T r a n s i t i o nF r o m = " M o u s e O v e r "T o = " N o r m a l " G e n e r a t e d D u r a t i o n = " 0 : 0 : 1 . 5 " > < S t o r y b o a r d > < C o l o r A n i m a t i o n U s i n g K e y F r a m e s S t o r y b o a r d . T a r g e t P r o p e r t y = " C o l o r " S t o r y b o a r d . T a r g e t N a m e = " B o r d e r B r u s h " F i l l B e h a v i o r = " H o l d E n d "> < C o l o r A n i m a t i o n U s i n g K e y F r a m e s . K e y F r a m e s > < L i n e a r C o l o r K e y F r a m eV a l u e = " B l u e " K e y T i m e = " 0 : 0 : 0 . 5 "/ > < L i n e a r C o l o r K e y F r a m eV a l u e = " Y e l l o w " K e y T i m e = " 0 : 0 : 1 "/ > < L i n e a r C o l o r K e y F r a m eV a l u e = " B l a c k " K e y T i m e = " 0 : 0 : 1 . 5 "/ > < / C o l o r A n i m a t i o n U s i n g K e y F r a m e s . K e y F r a m e s > < / C o l o r A n i m a t i o n U s i n g K e y F r a m e s > < / S t o r y b o a r d > < / V i s u a l T r a n s i t i o n > < / V i s u a l S t a t e G r o u p . T r a n s i t i o n s > < ! T h er e m a i n d e ro ft h eV i s u a l S t a t e G r o u pi st h e
msdn.microsoft.com/en-us/library/ee230084(d=printer,v=vs.110).aspx 10/18
12/19/13
< ! T h er e m a i n d e ro ft h eV i s u a l S t a t e G r o u pi st h e s a m ea st h ep r e v i o u se x a m p l e . > < V i s u a l S t a t eN a m e = " N o r m a l "/ > < V i s u a l S t a t eN a m e = " M o u s e O v e r " > < S t o r y b o a r d > < C o l o r A n i m a t i o n S t o r y b o a r d . T a r g e t N a m e = " B o r d e r B r u s h " S t o r y b o a r d . T a r g e t P r o p e r t y = " C o l o r " T o = " R e d "/ > < / S t o r y b o a r d > < / V i s u a l S t a t e > < V i s u a l S t a t eN a m e = " P r e s s e d " > < S t o r y b o a r d > < C o l o r A n i m a t i o n S t o r y b o a r d . T a r g e t N a m e = " B o r d e r B r u s h " S t o r y b o a r d . T a r g e t P r o p e r t y = " C o l o r " T o = " T r a n s p a r e n t " / > < / S t o r y b o a r d > < / V i s u a l S t a t e >
The following example shows the TemplatePartAttribute objects that are specified on the ComboBox class. The logic of
11/18
12/19/13
The following example shows the TemplatePartAttribute objects that are specified on the ComboBox class. The logic of ComboBox expects to find a TextBox named P A R T _ E d i t a b l e T e x t B o xand a Popup named P A R T _ P o p u pin its ControlTemplate. C# [ T e m p l a t e P a r t A t t r i b u t e ( N a m e=" P A R T _ E d i t a b l e T e x t B o x " ,T y p e=t y p e o f ( T e x t B o x ) ) ] [ T e m p l a t e P a r t A t t r i b u t e ( N a m e=" P A R T _ P o p u p " ,T y p e=t y p e o f ( P o p u p ) ) ] p u b l i cc l a s sC o m b o B o x:I t e m s C o n t r o l { } The following example shows a simplified ControlTemplate for the ComboBox that includes the elements that are specified by the TemplatePartAttribute objects on the ComboBox class. XAML < C o n t r o l T e m p l a t eT a r g e t T y p e = " C o m b o B o x " > < G r i d > < T o g g l e B u t t o nx : N a m e = " D r o p D o w n T o g g l e " H o r i z o n t a l A l i g n m e n t = " S t r e t c h "V e r t i c a l A l i g n m e n t = " S t r e t c h " M a r g i n = " 1 "H o r i z o n t a l C o n t e n t A l i g n m e n t = " R i g h t " I s C h e c k e d = " { B i n d i n gP a t h = I s D r o p D o w n O p e n , M o d e = T w o W a y , R e l a t i v e S o u r c e = { R e l a t i v e S o u r c eT e m p l a t e d P a r e n t } } " > < P a t hx : N a m e = " B t n A r r o w "H e i g h t = " 4 "W i d t h = " 8 " S t r e t c h = " U n i f o r m "M a r g i n = " 0 , 0 , 6 , 0 " F i l l = " B l a c k " D a t a = " F 1M3 0 0 , 1 9 0 L3 1 0 , 1 9 0 L3 0 5 , 1 8 3 L3 0 1 , 1 9 0Z"/ > < / T o g g l e B u t t o n > < C o n t e n t P r e s e n t e rx : N a m e = " C o n t e n t P r e s e n t e r "M a r g i n = " 6 , 2 , 2 5 , 2 " C o n t e n t = " { T e m p l a t e B i n d i n gS e l e c t i o n B o x I t e m } " C o n t e n t T e m p l a t e = " { T e m p l a t e B i n d i n gS e l e c t i o n B o x I t e m T e m p l a t e } " C o n t e n t T e m p l a t e S e l e c t o r = " { T e m p l a t e B i n d i n gI t e m T e m p l a t e S e l e c t o r } " > < / C o n t e n t P r e s e n t e r > < T e x t B o xx : N a m e = " P A R T _ E d i t a b l e T e x t B o x " S t y l e = " { x : N u l l } " F o c u s a b l e = " F a l s e " B a c k g r o u n d = " { T e m p l a t e B i n d i n gB a c k g r o u n d } " H o r i z o n t a l A l i g n m e n t = " L e f t " V e r t i c a l A l i g n m e n t = " C e n t e r " M a r g i n = " 3 , 3 , 2 3 , 3 " V i s i b i l i t y = " H i d d e n " I s R e a d O n l y = " { T e m p l a t e B i n d i n gI s R e a d O n l y } " / > < P o p u px : N a m e = " P A R T _ P o p u p " I s O p e n = " { T e m p l a t e B i n d i n gI s D r o p D o w n O p e n } " > < B o r d e rx : N a m e = " P o p u p B o r d e r " H o r i z o n t a l A l i g n m e n t = " S t r e t c h "H e i g h t = " A u t o " M i n W i d t h = " { T e m p l a t e B i n d i n gA c t u a l W i d t h } " M a x H e i g h t = " { T e m p l a t e B i n d i n gM a x D r o p D o w n H e i g h t } " B o r d e r T h i c k n e s s = " { T e m p l a t e B i n d i n gB o r d e r T h i c k n e s s } " B o r d e r B r u s h = " B l a c k "B a c k g r o u n d = " W h i t e "C o r n e r R a d i u s = " 3 " > < S c r o l l V i e w e rx : N a m e = " S c r o l l V i e w e r "B o r d e r T h i c k n e s s = " 0 "P a d d i n g = " 1 " > < I t e m s P r e s e n t e r / > < / S c r o l l V i e w e r > < / B o r d e r > < / P o p u p > < / G r i d > < / C o n t r o l T e m p l a t e >
msdn.microsoft.com/en-us/library/ee230084(d=printer,v=vs.110).aspx
12/18
12/19/13
< / C o n t r o l T e m p l a t e >
13/18
12/19/13
p u b l i cD a t a T e m p l a t eC o n t e n t T e m p l a t e{g e t ;s e t ;} p u b l i cF o n t F a m i l yF o n t F a m i l y{g e t ;s e t ;} p u b l i cd o u b l eF o n t S i z e{g e t ;s e t ;} p u b l i cF o n t S t r e t c hF o n t S t r e t c h{g e t ;s e t ;} p u b l i cF o n t S t y l eF o n t S t y l e{g e t ;s e t ;} p u b l i cF o n t W e i g h tF o n t W e i g h t{g e t ;s e t ;} p u b l i cB r u s hF o r e g r o u n d{g e t ;s e t ;} p u b l i cH o r i z o n t a l A l i g n m e n tH o r i z o n t a l C o n t e n t A l i g n m e n t{g e t ;s e t ;} p u b l i cT h i c k n e s sP a d d i n g{g e t ;s e t ;} p u b l i cT e x t A l i g n m e n tT e x t A l i g n m e n t{g e t ;s e t ;} p u b l i cT e x t D e c o r a t i o n C o l l e c t i o nT e x t D e c o r a t i o n s{g e t ;s e t ;} p u b l i cT e x t W r a p p i n gT e x t W r a p p i n g{g e t ;s e t ;} p u b l i cV e r t i c a l A l i g n m e n tV e r t i c a l C o n t e n t A l i g n m e n t{g e t ;s e t ;} } When creating a ControlTemplate, it is often easiest to begin with an existing ControlTemplate and make changes to it. You can do one of the following to change an existing ControlTemplate: Use a designer, such as Expression Blend, which provides a graphical user interface for creating control templates. For more information, see Styling a control that supports templates. Get the default ControlTemplate and edit it. To find the default control templates that are included with WPF, see Default WPF Themes.
Complete Example
The following example shows the complete Button ControlTemplate that is discussed in this topic. XAML < S t a c k P a n e l > < S t a c k P a n e l . R e s o u r c e s > < S t y l eT a r g e t T y p e = " B u t t o n "x : K e y = " n e w T e m p l a t e " > < ! S e tt h eB a c k g r o u n d ,F o r e g r o u n d ,F o n t S i z e ,W i d t h , H e i g h t ,M a r g i n ,a n dT e m p l a t ep r o p e r t i e sf o r t h eB u t t o n . > < S e t t e rP r o p e r t y = " B a c k g r o u n d "V a l u e = " N a v y " / > < S e t t e rP r o p e r t y = " F o r e g r o u n d "V a l u e = " W h i t e " / > < S e t t e rP r o p e r t y = " F o n t S i z e "V a l u e = " 1 4 " / > < S e t t e rP r o p e r t y = " W i d t h "V a l u e = " 1 0 0 " / > < S e t t e rP r o p e r t y = " H e i g h t "V a l u e = " 4 0 " / > < S e t t e rP r o p e r t y = " M a r g i n "V a l u e = " 1 0 " / > < S e t t e rP r o p e r t y = " H o r i z o n t a l C o n t e n t A l i g n m e n t "V a l u e = " C e n t e r " / > < S e t t e rP r o p e r t y = " V e r t i c a l C o n t e n t A l i g n m e n t "V a l u e = " C e n t e r " / > < S e t t e rP r o p e r t y = " T e m p l a t e " > < S e t t e r . V a l u e > < C o n t r o l T e m p l a t eT a r g e t T y p e = " B u t t o n " > < B o r d e rx : N a m e = " R o o t E l e m e n t " > < V i s u a l S t a t e M a n a g e r . V i s u a l S t a t e G r o u p s > < ! D e f i n et h es t a t e sa n dt r a n s i t i o n sf o rt h ec o m m o ns t a t e s . T h es t a t e si nt h eV i s u a l S t a t e G r o u pa r em u t u a l l ye x c l u s i v et o e a c ho t h e r . > < V i s u a l S t a t e G r o u pN a m e = " C o m m o n S t a t e s " >
msdn.microsoft.com/en-us/library/ee230084(d=printer,v=vs.110).aspx 14/18
12/19/13
< ! D e f i n et h eV i s u a l T r a n s i t i o n st h a tc a nb eu s e dw h e nt h ec o n t r o l t r a n s i t i o n sb e t w e e nV i s u a l S t a t e st h a ta r ed e f i n e di nt h e V i s u a l S t a t G r o u p . > < V i s u a l S t a t e G r o u p . T r a n s i t i o n s > < ! T a k eo n eh u n d r e d t ho fas e c o n dt ot r a n s i t i o nt ot h e P r e s s e ds t a t e . > < V i s u a l T r a n s i t i o nT o = " P r e s s e d " G e n e r a t e d D u r a t i o n = " 0 : 0 : 0 . 0 1 "/ > < ! T a k eo n eh a l fs e c o n dt ot r a s i t i o nt ot h eM o u s e O v e rs t a t e . > < V i s u a l T r a n s i t i o nT o = " M o u s e O v e r " G e n e r a t e d D u r a t i o n = " 0 : 0 : 0 . 5 "/ > < ! T a k eo n eh u n d r e d t ho fas e c o n dt ot r a n s i t i o nf r o mt h e P r e s s e ds t a t et ot h eM o u s e O v e rs t a t e . > < V i s u a l T r a n s i t i o nF r o m = " P r e s s e d "T o = " M o u s e O v e r " G e n e r a t e d D u r a t i o n = " 0 : 0 : 0 . 0 1 "/ > < ! T a k eo n ea n dah a l fs e c o n d st ot r a n s i t i o nf r o mt h e M o u s e O v e rs t a t et ot h eN o r m a ls t a t e . H a v et h eS o l i d C o l o r B r u s h ,B o r d e r B r u s h ,f a d et ob l u e , t h e nt oy e l l o w ,a n dt h e nt ob l a c ki nt h a tt i m e . > < V i s u a l T r a n s i t i o nF r o m = " M o u s e O v e r "T o = " N o r m a l " G e n e r a t e d D u r a t i o n = " 0 : 0 : 1 . 5 " > < S t o r y b o a r d > < C o l o r A n i m a t i o n U s i n g K e y F r a m e s S t o r y b o a r d . T a r g e t P r o p e r t y = " C o l o r " S t o r y b o a r d . T a r g e t N a m e = " B o r d e r B r u s h " F i l l B e h a v i o r = " H o l d E n d "> < C o l o r A n i m a t i o n U s i n g K e y F r a m e s . K e y F r a m e s > < L i n e a r C o l o r K e y F r a m eV a l u e = " B l u e " K e y T i m e = " 0 : 0 : 0 . 5 "/ > < L i n e a r C o l o r K e y F r a m eV a l u e = " Y e l l o w " K e y T i m e = " 0 : 0 : 1 "/ > < L i n e a r C o l o r K e y F r a m eV a l u e = " B l a c k " K e y T i m e = " 0 : 0 : 1 . 5 "/ > < / C o l o r A n i m a t i o n U s i n g K e y F r a m e s . K e y F r a m e s > < / C o l o r A n i m a t i o n U s i n g K e y F r a m e s > < / S t o r y b o a r d > < / V i s u a l T r a n s i t i o n > < / V i s u a l S t a t e G r o u p . T r a n s i t i o n s > < ! T h eN o r m a ls t a t ei st h es t a t et h eb u t t o ni si n w h e ni ti sn o ti na n o t h e rs t a t ef r o mt h i sV i s u a l S t a t e G r o u p . T h e r ei sn os p e c i a lv i s u a lb e h a v i o rf o rt h i ss t a t e ,b u t t h eV i s u a l S t a t em u s tb ed e f i n e di no r d e rf o rt h eb u t t o n t or e t u r nt oi t si n i t i a ls t a t e . > < V i s u a l S t a t ex : N a m e = " N o r m a l "/ > < ! C h a n g et h eb o r d e ro ft h eb u t t o nt or e dw h e nt h e m o u s ei so v e rt h eb u t t o n . > < V i s u a l S t a t ex : N a m e = " M o u s e O v e r " > < S t o r y b o a r d > < C o l o r A n i m a t i o nS t o r y b o a r d . T a r g e t N a m e = " B o r d e r B r u s h " S t o r y b o a r d . T a r g e t P r o p e r t y = " C o l o r "
msdn.microsoft.com/en-us/library/ee230084(d=printer,v=vs.110).aspx
15/18
12/19/13
< / S t o r y b o a r d > < / V i s u a l S t a t e > < ! C h a n g et h eb o r d e ro ft h eb u t t o nt oT r a n s p a r e n tw h e nt h e b u t t o ni sp r e s s e d . > < V i s u a l S t a t ex : N a m e = " P r e s s e d " > < S t o r y b o a r d> < C o l o r A n i m a t i o nS t o r y b o a r d . T a r g e t N a m e = " B o r d e r B r u s h " S t o r y b o a r d . T a r g e t P r o p e r t y = " C o l o r " T o = " T r a n s p a r e n t " / > < / S t o r y b o a r d > < / V i s u a l S t a t e > < ! S h o wt h eD i s a b l e d R e c tw h e nt h eI s E n a b l e dp r o p e r t yo n t h eb u t t o ni sf a l s e . > < V i s u a l S t a t ex : N a m e = " D i s a b l e d " > < S t o r y b o a r d > < D o u b l e A n i m a t i o nS t o r y b o a r d . T a r g e t N a m e = " D i s a b l e d R e c t " S t o r y b o a r d . T a r g e t P r o p e r t y = " O p a c i t y " T o = " 1 "D u r a t i o n = " 0 "/ > < / S t o r y b o a r d > < / V i s u a l S t a t e > < / V i s u a l S t a t e G r o u p > < ! D e f i n et h es t a t e sa n dt r a n s i t i o n sf o rt h ef o c u ss t a t e s . T h es t a t e si nt h eV i s u a l S t a t e G r o u pa r em u t u a l l ye x c l u s i v et o e a c ho t h e r . > < V i s u a l S t a t e G r o u px : N a m e = " F o c u s S t a t e s " > < ! D e f i n et h eV i s u a l S t a t e si nt h i sV i s t u a l S t a t e G r o u p . > < V i s u a l S t a t ex : N a m e = " F o c u s e d " > < S t o r y b o a r d > < O b j e c t A n i m a t i o n U s i n g K e y F r a m e s S t o r y b o a r d . T a r g e t N a m e = " F o c u s V i s u a l " S t o r y b o a r d . T a r g e t P r o p e r t y = " V i s i b i l i t y "D u r a t i o n = " 0 " > < D i s c r e t e O b j e c t K e y F r a m eK e y T i m e = " 0 " > < D i s c r e t e O b j e c t K e y F r a m e . V a l u e > < V i s i b i l i t y > V i s i b l e < / V i s i b i l i t y > < / D i s c r e t e O b j e c t K e y F r a m e . V a l u e > < / D i s c r e t e O b j e c t K e y F r a m e > < / O b j e c t A n i m a t i o n U s i n g K e y F r a m e s > < / S t o r y b o a r d > < / V i s u a l S t a t e > < V i s u a l S t a t ex : N a m e = " U n f o c u s e d " > < S t o r y b o a r d > < O b j e c t A n i m a t i o n U s i n g K e y F r a m e s S t o r y b o a r d . T a r g e t N a m e = " F o c u s V i s u a l " S t o r y b o a r d . T a r g e t P r o p e r t y = " V i s i b i l i t y " D u r a t i o n = " 0 " > < D i s c r e t e O b j e c t K e y F r a m eK e y T i m e = " 0 " > < D i s c r e t e O b j e c t K e y F r a m e . V a l u e > < V i s i b i l i t y > C o l l a p s e d < / V i s i b i l i t y > < / D i s c r e t e O b j e c t K e y F r a m e . V a l u e > < / D i s c r e t e O b j e c t K e y F r a m e >
msdn.microsoft.com/en-us/library/ee230084(d=printer,v=vs.110).aspx
16/18
12/19/13
< / D i s c r e t e O b j e c t K e y F r a m e > < / O b j e c t A n i m a t i o n U s i n g K e y F r a m e s > < / S t o r y b o a r d > < / V i s u a l S t a t e > < / V i s u a l S t a t e G r o u p > < / V i s u a l S t a t e M a n a g e r . V i s u a l S t a t e G r o u p s > < ! C r e a t et h eS o l i d C o l o r B r u s hf o rt h eB a c k g r o u n d a sa no b j e c te l e m m e n ta n dg i v ei tan a m es o i tc a nb er e f e r r e dt oe l s e w h e r ei nt h ec o n t r o lt e m p l a t e . > < B o r d e r . B a c k g r o u n d > < S o l i d C o l o r B r u s hx : N a m e = " B o r d e r B r u s h "C o l o r = " B l a c k " / > < / B o r d e r . B a c k g r o u n d > < ! C r e a t eab o r d e rt h a th a sad i f f e r e n tc o l o rb ya d d i n gs m a l l e rg r i d . T h eb a c k g r o u n do ft h i sg r i di ss p e c i f i e db yt h eb u t t o n ' sB a c k g r o u n d p r o p e r t y . > < G r i dB a c k g r o u n d = " { T e m p l a t e B i n d i n gB a c k g r o u n d } "M a r g i n = " 4 " > < ! C r e a t eaR e c t a n g l et h a ti n d i c a t e st h a tt h e B u t t o nh a sf o c u s . > < R e c t a n g l eN a m e = " F o c u s V i s u a l " V i s i b i l i t y = " C o l l a p s e d "M a r g i n = " 2 " S t r o k e = " { T e m p l a t e B i n d i n gF o r e g r o u n d } " S t r o k e T h i c k n e s s = " 1 " S t r o k e D a s h A r r a y = " 1 . 51 . 5 " / > < ! U s eaC o n t e n t P r e s e n t e rt od i s p l a yt h eC o n t e n to f t h eB u t t o n . > < C o n t e n t P r e s e n t e r H o r i z o n t a l A l i g n m e n t = " { T e m p l a t e B i n d i n gH o r i z o n t a l C o n t e n t A l i g n m e n t } " V e r t i c a l A l i g n m e n t = " { T e m p l a t e B i n d i n gV e r t i c a l C o n t e n t A l i g n m e n t } " M a r g i n = " 4 , 5 , 4 , 4 "/ > < ! C r e a t ear e c t a n g l et h a tc a u s e st h eb u t t o nt oa p p e a r g r a y e do u tw h e ni ti sd i s a b l e d . > < R e c t a n g l ex : N a m e = " D i s a b l e d R e c t " F i l l = " # A 5 F F F F F F " O p a c i t y = " 0 "I s H i t T e s t V i s i b l e = " f a l s e "/ > < / G r i d > < / B o r d e r > < / C o n t r o l T e m p l a t e > < / S e t t e r . V a l u e > < / S e t t e r > < / S t y l e > < / S t a c k P a n e l . R e s o u r c e s > < B u t t o nS t y l e = " { S t a t i c R e s o u r c en e w T e m p l a t e } " C o n t e n t = " B u t t o n 1 " / > < B u t t o nS t y l e = " { S t a t i c R e s o u r c en e w T e m p l a t e } " B a c k g r o u n d = " P u r p l e " C o n t e n t = " B u t t o n 2 "/ > < / S t a c k P a n e l >
See Also
msdn.microsoft.com/en-us/library/ee230084(d=printer,v=vs.110).aspx 17/18
12/19/13
See Also
Concepts
Styling and Templating
msdn.microsoft.com/en-us/library/ee230084(d=printer,v=vs.110).aspx
18/18