Is it possible to set a font for a screen in wpf. I mean if i am able to set a font property to Tahoma, all the text[including user controls] displayed in that particular screen uses the font Tahoma. Right now i am manually changing the fonts of all the text elements.
Thanks,
Generally if you set the FontFamily of a Window to Tahoma, the text in the majority of controls shoud use that font because of property value inheritance. For example Button and TextBlock should do that.
Anyway there are few controls such as StatusBar, Menu, and ToolTip that set internally their font type to the font system setting (which the user can change with the Window Control Panel). As a consequence these elements will ignore the font settings in the window.
The Window is a Control from which it derives the FontFamily-property. By inheritance all the font family is set on all underlying Controls.
I think you need to consider using WPF-Styles, for example:
<Style TargetType="{x:Type Button}">
<Setter Property="Control.FontFamily" Value="Showcard Gothic"/>
</Style>
will set all Buttons to this font family based on which scope (Window or Application, for instance) you define your resources.
Related
Does anyone know how to set the default font (color, in this case) across an entire Silverlight Application?
It's a rather large legacy application so I don't think I can take advantage of themes. I've created styles etc but don't fancy doing this across the whole app, and them maintaining them etc..
I don't have much Silverlight/Xaml experience so please detail your answer like I'm stupid!
Thanks
If you wrap your entire application with a ContentControl and specify its Foreground, all controls inherit the Foreground color. If one of your resource file specify the Foreground for any of your child controls, the Foreground should flow down to all of them... :(
Another solution is to use implicit style like in Silverlight toolkit theme files. You can see one resource for the font color and this color is applied on each UI controls via implicit style.
Theme.xaml
<SolidColorBrush x:Key="TextBrush" Color="#FF152937" />
...
<Style TargetType="Button">
<Setter Property="Foreground" Value="{StaticResource TextBrush}" />
So if your resources files override Foreground properties, you have to change that like in Theme.xaml toolkit file. Create a unique Foreground Brush and apply with implicit style on each control.
If someone has a better solution ???
This question is in regard to the Telerik RadButtons for Silverlight. I have themes per customer on the site where Silverlight is used. I am able to change the background and foreground colors by setting the Background and Foreground brush properties. However, the styles revert to the standard colors while hovering over the button. How do I change the colors for all button states?
I attempted to set the Resources dictionary as shown on Telerik Styles, but it appears to be read-only.
More information on how to style a RadButton you can find here: http://www.telerik.com/help/silverlight/radbuttons-styles-and-templates-overview.html
When creating an app based on the Silverlight Business Application template, a number of styles are generated in Styles.xaml. These, for the most part, are self-explanatory.
I am interested in giving the Login form a dark background, which I can accomplish by manipulating the LogRegWindowStyle style. Now, I want to change the default black text of the User name and Password labels to something lighter, but what do I do?
The LoginTextStyle style seems to be the most likely candidate but it is not referenced anywhere and setting a Foreground value does not seem to have an effect. So why is it there?
Finally, the labels turn red when an error occurs so is this achieved by a style or is it hard-coded somewhere? How would I change it if there wasn't enough contrast with the background?
the login text style is inherited from the loginFrom style LoginDataFormStyle. If you set a Foreground color in the LoginDataFormStyle, the foreground of the text will also be changed.
<!-- LoginDataForm Style -->
<Style x:Key="LoginDataFormStyle" TargetType="dataControls:DataForm">
<Setter Property="Foreground" Value="Gray"/>
To change the color of the Labels, you can create your own DataTemplate of your loginFrom and put in whatever Labels you need. Then you can create a style for your Label and change the Color from 'Red'(default color) to something you like in the Label's Invalid visual state.
Hope this helps. :)
I am extending the WPF textbox in order to place a custom image on it. I want to capture mouse clicks on this image. So far i have been able to use arrangeOverride to place the image in where i need it but since it happens to be placed "inside" the text box, whenever i try clicking it the text box captures the click and the event that is attached to the image does not fire. Is it possible to indicate that the image should be placed on top of the text box when using arrange override? I know i can get around this issue if i extended a Control and placed a text box inside it, but for my application i need to actually extend a text box in order to be able to use it in another more complex control that is currently using a text box.
Thanks!
ArrangeOverride may not be the ideal solution for this. A better approach would probably be to use control templating: create a ControlTemplate containing a Grid with a single cell, and place the Image and the text box content host in that single cell. You can place the Image on top implicitly by the order you place the controls, or explicitly by setting the Panel.ZIndex attached property.
The one trick here is knowing how to represent the text box content host. This has to be a ScrollViewer with the name PART_ContentHost. So your template will look something like:
<ControlTemplate TargetType="{x:Type Ambog36sTextBox}">
<Grid>
<ScrollViewer x:Name="PART_ContentHost" /> <!-- WPF will fill in a text edit area here -->
<Image Panel.ZIndex="1" Source="..." />
</Grid>
</ControlTemplate>
Then assign this template to your custom text box class via the default style in the usual way.
As you are not using the standard composition model it means you need to override the mouse handling before it reaches the text box code and add your own custom logic to decide on the events to generate.
In Expression Blend you can create a font-size of say 18 and then create a "font-size resource".
Coming at this from HTML/CSS, I cannot think of when I would want to make a style for a "font-size" and one for a "font-style" and one for a "font-weight". Instead I want to make a font called "CompanyHeader" and have 10 different attributes set in it, e.g. font-weight, font-style, font-size, color,etc.
Why is this different in Expression Blend, XAML, what is the sense of making a style/resource for each attribute?
this graphic shows how you can click on a little button on each attribute to change it into a resource:
alt text http://tanguay.info/web/external/blendStyles.png
I have no experience with Blend, but styles in XAML can include more than one attribute, more then that, since unlike css you can only apply one style to an element you can't combine multiple one-attribute styles.
Here is an example for a style that set multiple properties:
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<Style x:Key="MyStyle" TargetType="{x:Type Label}">
<Setter Property="Width" Value="125"/>
<Setter Property="Height" Value="25"/>
<Setter Property="Background" Value="Red"/>
</Style>
</Page.Resources>
<Label Style="{StaticResource MyStyle}"/>
</Page>
Note that if I wanted to break the style into 3 smaller styles each setting one property I couldn't use them because the Label's Style property can only accept one style.
I think they likely allow for the creation of single resources for FontFamily, FontWeight, etc. to allow them to be used across many styles in the application. By placing a single property in a resource you can effect all styles using that resource at once. If you weren't using a resource but were attempting to use a consistent FontFamily across your whole application (or a portion of it) then you had to go through each style one at a time in order to update it.
In order to make a style with multiple properties in blend you can do the following:
Select the control you wish to style (the control's type will be used as the TargetType for the style)
From the menu select Object->Edit Style->Create Empty
Enter the Key you would like to assign to the style (this is the name that you will use to reference the style)
Go to the properties tab and begin to apply the look/feel that you want for that style
It allows you to reuse the font details at am more granular level than having to define all elements of the font definition. You might have several styles that all inherit from the same font-size definition. Your designer can then change the font-size and all the styles that use it then automatically have an updated appearance.
Each instance of a font will use its own resources, doesn't matter if multiple such defenitions refer to same font.
Using same font in two different styles will end-up with two instances of the font (when the styles are applied). Instade, you can defined the font as a style of its own and use the style with-in other styles. In this case, once runtime instance of the font resource is used by both styles.
If you have very complex resource dictionaries (say for example you are creating a theme), it is a good idea to define geanular assets (like a specific color brush or font) as independent resource (or named style) and use them in other complex styles to conserve system resources.
On your question on Blend, it simpley enforces this best practice.
This is possible by creating a helper class to use and wrap your styles. CompoundStyle mentioned here shows how to do it. There are multiple ways, but the easiest is to do the following:
<TextBlock Text="Test"
local:CompoundStyle.StyleKeys="headerStyle,textForMessageStyle,centeredStyle"/>
The blog post talks about Win8 and Windows Phone, but the same code works for WPF as well (minus the Utilies class which is not needed)
Hope that helps.