c# - How can I apply a style to all buttons? -


how , create style gives button controls have resource blue (yellow border, blue background)?

can added texbox well?

is there centralized place, since want style able affect buttons in different pages in app?

in these cases may use styles:

  • you going apply same properties (or members) on several controls of type
  • you going make save , desired state of type , use later.

you can add style in control's resources or resourcedictionaries this:

<style targettype="button">     <setter property="borderbrush" value="yellow"/>     <setter property="background" value="blue"/> </style> 

if define x:key, should explicitly button follows style (e.g. <button style="{staticresource mybuttonstylekey}">) otherwise style automatically apply on buttons.

edit: add resourcedictionary (named mystyles.xaml) project (in folder named myresource). here code:

<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">     <style targettype="button">         <setter property="borderbrush" value="yellow"/>         <setter property="background" value="blue"/>     </style> </resourcedictionary>  

then in app.xaml add this:

<application x:class="wpfapp.app"          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"          startupuri="mainwindow.xaml">     <application.resources>         <resourcedictionary>             <resourcedictionary.mergeddictionaries>                 <resourcedictionary source="myresource/mystyles.xaml"/>             </resourcedictionary.mergeddictionaries>         </resourcedictionary>     </application.resources> </application> 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -