So I'm trying to take advantage of all the TextOptions introduced in SL5 (TextRenderingMode, TextHintingMode, TextFormattingMode) and get a nice uniform (performance minded) Segeo UI font throughout an app.
My problem lies in the fact that these don't seem to be getting inherited through all the controls. I set them as resources like;
<TextFormattingMode x:Key="THETextFormattingMode">Display</TextFormattingMode>
<TextHintingMode x:Key="THETextHintingMode">Fixed</TextHintingMode>
<TextRenderingMode x:Key="THETextRenderingMode">Auto</TextRenderingMode>
Then I have them set as setters on individual controls like TextBlock and TextBox like;
<Setter Property="TextOptions.TextFormattingMode" Value="{StaticResource THETextFormattingMode}" />
<Setter Property="TextOptions.TextHintingMode" Value="{StaticResource THETextHintingMode}" />
<Setter Property="TextOptions.TextRenderingMode" Value="{StaticResource THETextRenderingMode}" />
Except I'm seeing discrepancies between the controls still, example image below with "tt" taken as a screen shot from the same screen. The "tt" on the left is from a TextBox and the one on the right is from a TextBlock which both have the TextOptions.*Mode set the same.
What am I missing here? Why are they not identical? The text from the TextBlock ("tt" image on the right) appears sharper.
Maybe different default colors in TextBlock and TextBox for Foreground and Background result in this effect when combined/overlapping.
Have you tried to set them both to Foreground="#FFFFFF" and Background="#000000"?
Related
I am looking for an example of a customized WPF button.
Ideally in a liked Blend/VS2013 configuration, i.e. a VS2013 test solution that includes a button project that can be edited in Blend for VS2013.
The button should have a visual appearance that makes it clear what state it is in, i.e.
Normal = default
MouseOver = inner glow
Pressed = smaller size / smaller shadow
ToggledOn = outer glow
Disabled = grayed out
Given such an example I could then just tweak the visual appearance of the states using Blend.
And on the application side I want to just instantiate the button, associate the style, and set properties for BackgroundColor, image/icon, text label, width, height.
I seems that using a ControlTemplate style is the recommended way of doing this, rather than sub-classing, see MSDN.
The three key issues seem to be:
how to setup the VS2013/blend project structure to use both interchangeably on a single set of source files
how to compute relative sizes in the ControlTemplate, i.e. what is the syntax for
Width = Button.Width x 1.1 to set a glow extend relative to the actual button size that is not in the template, but to be defined on the client application UI design.
how to compute relative colors from the base color of the button, i.e. what is the WPF XAML syntax for GradientStop Color = Button.BackgroundColor x 80% + White x 20%
This should be a very common need, but Google was not helpful in finding anything like the above.
Any help with any one of the three key issues would be greatly appreciated.
Your requirements do not require defining a new ControlTemplate and can be achieved with a Style with Triggers, e.g.:
<Grid>
<Grid.Resources>
<Style TargetType="Button">
<Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
<Style.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="0.75" ScaleY="0.75"/>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</Grid.Resources>
<Button Content="Click Me!" />
</Grid>
The Style can be accessible anywhere in the application if defined in your App.xaml Resources and given an x:Key
Using ScaleTransform's ScaleX and ScaleY are relative values.
You will need your own IValueConverter then bind the target color to a source color using your converter.
I'm trying to figure out how to increase the popup height of WPF Toolkit's AutoCompleteBox. Right now, only few items fit in the popup. How do I make it taller? I see there is a MaxPopupHeight property. What about min height?
I don't know if this is exactly what you want, but a thing I've found useful is to specify an explicit height for the popup:
<tk:AutoCompleteBox ...>
<tk:AutoCompleteBox.Resources>
<Style TargetType="{x:Type Popup}">
<Setter Property="Height" Value="200" />
</Style>
</tk:AutoCompleteBox.Resources>
</tk:AutoCompleteBox>
This also helps with the problem of Toolkit's AutoCompleteBox ignoring MaxDropDownHeight as several people have encountered.
Actually now I see that it's pretty much an elaboration on a solution proposed by Zabavsky.
I have a StatusBar below the screen in SL4 (using PRISM), just a very simple Telerik RadDockPanel.
I also have a menu (Telerik RibbonView with RadRibbonGroup and RadRibbonToggleButton). When the toggle button is pressed, I want to set the text to 'ON' and 'OFF', and I want to hide the status bar, but... only in XAML (not using code behind).
I believe this is a common SL/WPF coding practice... but how ?
Have to use EventTrigger (check example bellow on page by link that I provided) and ObjectAnimationUsingKeyFrames to change properties that aren't animated (Text, Visibility so on).
Check good example in other answer on so.
You can specify a DataTrigger in your window like this -
<StatusBar.Style>
<Style>
<Style.Triggers>
<DataTrigger
Binding="{Binding ElementName=MyRadRibbonToggleButton, Path=IsChecked}"
Value="True">
<Setter Property="Grid.Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</StatusBar.Style>
In case you can't use ElementName binding then you can use a property in your ViewModel(corresponding to RadRibbonToggleButton state). Similar Trigger can be created for a TextBlock/Label to show On/Off text.
This is how I implement this kind of functionality in WPF/MVVM applications;
You may have to apply some hack to make this work with telerik controls.
I have an application resource of the following
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Background" Value="{DynamicResource windowTextBackColor}"/>
<Setter Property="Foreground" Value="{DynamicResource windowsTextForeColor}"/>
</Style>
So all the text blocks in my application should assume those colours.
However the Menu and its containing MenuItems on my Main Window does not take these colours?
I have to do the XAML
for it to assume those colours, Is there a reason why setting a style that targets Text blocks does not work?
Thanks
I think you have to style the menu and menuitems separately. A MenuItem is a HeaderedContentControl, and its Header property is not a TextBlock, but an object, so it wouldn't be affected by a style for TextBlock.
You might also try changing that style to target Control instead of TextBlock. (Control is where Foreground and Background are defined.) I can't say for sure that it'll work, but if it does, it'll make every Control (TextBlocks, MenuItems, Buttons...) have those background and foreground colors.
Also, you might consider using BasedOn so that you can "inherit" the styles. If you don't, then styles defined farther up the hierarchy won't affect controls that have a style defined lower in the hierarchy. Basically, the lower ones mask the higher ones, unless you used BasedOn. Use it in this fashion:
BasedOn="{StaticResource {x:Type <your type here>}}"
I'd like to give every Control a certain FontFamily and FontWeight in Silverlight 4.0. I know that styles can now apply to all controls of a certain type, so I tried this:
<Style TargetType="Control">
<Setter Property="FontFamily" Value="Arial" />
<Setter Property="FontWeight" Value="Bold" />
</Style>
Unfortunately, that doesn't appear to work. I can do this for types that derive from Control, however. For example, setting TargetType to Button applies those values to every Button in my application.
Why can't I do this for the Control base class, then?
The control styling being tied to the type system can be a bit misleading. Its actually based on the value of the controls DefaultStyleKey property. In the case of a Button the value is typeof(Button) and for a TextBox it is typeof(Textbox).
A default style will be applied to a control if the TargetType value equals the controls DefaultStyleKey value. There is no examination of whether the Type in the DefaultStyleKey is a derivative of the TargetType.
Font related properties are a special case since most controls will inherit the values for Font properties from the containing context. Hence you can effectively acheive the same result by specifying FontFamily and FontWeight on the UserControl element.
Edit
From a comment by the OP:-
I was hoping that I could set it in one place and have every UserControl in the entire application take on that style.
The closest you can get to that is to place a keyed style in the app resources and ensure all the usercontrols bind to that style. Of course this still requires some co-operation for each user control but at least the font choices remain in a single place.
For example in app.xaml:-
<Style x:Key="Common" TargetType="UserControl">
<Setter Property="FontFamily" Value="Arial" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Foreground" Value="Blue" />
Then in each usercontrol:-
<UserControl ...namespace stuff here...
Style="{StaticResource Common}">
<!-- ... content here ... -->
I do it by specifying FontFamily in my root visual. All child controls without explicit FontFamily set, derive FontFamily from the root visual.
Only ChildWindow needs extra FontFamily setting, because it is hosted in "über" root visual (as popup).
This would be of help:
this.RootVisual = New MainPage();
(MainPage)this.RootVisual.FontFamily
= New System.Windows.Media.FontFamily(
"/SLApplication;component/Fonts/segoeui.ttf#Segoe UI");