WPF some letter bigger then other letters in TextBlock - wpf

I use Nunito font in my WPF application and when font size set up for 12 units i get text like this
You can see that the a N letter is bigger than other (there is also some other letters have this kind an error)
Here's the style of my TextBlock:
<Style TargetType="{x:Type TextBlock}" x:Key="text-secondary-base">
<Setter Property="FontFamily" Value="{DynamicResource nunito-regular}"/>
<Setter Property="FontSize" Value="12" />
<Setter Property="LineHeight" Value="14" />
<Setter Property="FontWeight" Value="Regular" />
</Style>
Is there's the way to fix that without increasing FontSize?

Related

Weird WPF Round TextBox

I am new to WPF and I am trying to do a rounded corner textbox. There are a lot of examples I gather from here. However I cannot seems to make it work. Below are the two ways I tried and the results I obtained.
First Way:
<SolidColorBrush x:Key="SubTransparentTextBoxBG" Color="#ffffff" Opacity="0.12"/>
<Style TargetType="TextBox">
<Style.Setters>
<Setter Property="Background" Value="{StaticResource SubTransparentTextBoxBG}" />
<Setter Property="FontSize" Value="24px" />
<Setter Property="FontFamily" Value="Segoe UI Semibold"/>
<Setter Property="Foreground" Value="White" />
<Setter Property="Padding" Value="10" />
<Setter Property="BorderBrush" Value="Red" />
<Setter Property="BorderThickness" Value="2"/>
</Style.Setters>
<Style.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</Style.Resources>
</Style>
Result:
Apparently all my Setters took effect but not the Corner Radius
Second Way:
<SolidColorBrush x:Key="SubTransparentTextBoxBG" Color="#ffffff" Opacity="0.12"/>
<Style TargetType="TextBox">
<Style.Setters>
<Setter Property="Background" Value="{StaticResource SubTransparentTextBoxBG}" />
<Setter Property="FontSize" Value="24px" />
<Setter Property="FontFamily" Value="Segoe UI Semibold"/>
<Setter Property="Foreground" Value="White" />
<Setter Property="Padding" Value="10" />
<Setter Property="BorderBrush" Value="Red" />
<Setter Property="BorderThickness" Value="2"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Border x:Name="border" CornerRadius="10" BorderBrush="#000" BorderThickness="2" Background="#fff"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
Result:
This time, only the Round Border takes place and the rest of the Setters' property are overwritten.
Can Someone Please Help to point out what are the mistakes in these two ways?
The best way to give the TextBox rounded corners is to overwrite the template.
The following is your Style, but fixed. It now contains the mandatory parts with their mandatory naming: a content host named PART_ContentHost. In order to make the style setters work, you need to bind the template's controls (in this case the Border properties) to the appropriate properties of the templated parent (the TextBox) using TemplateBinding.
<Style TargetType="TextBox">
<Style.Setters>
<Setter Property="Background"
Value="{StaticResource SubTransparentTextBoxBG}" />
<Setter Property="FontSize"
Value="24px" />
<Setter Property="FontFamily"
Value="Segoe UI Semibold" />
<Setter Property="Foreground"
Value="White" />
<Setter Property="Padding"
Value="10" />
<Setter Property="BorderBrush"
Value="Red" />
<Setter Property="BorderThickness"
Value="2" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Border CornerRadius="10"
Margin="{TemplateBinding Margin}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}">
<!-- The required part with the required name -->
<ScrollViewer x:Name="PART_ContentHost"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
Wrapping the TextBox in a Border with rounded corners will still leave the TexBox with sharp corners that will overlap the rounded corners of the surrounding Border.
Some controls have mandatory template elements (parts) which must be part of the ContorlTemplate and have a special name. When those parts are missing or the name doesn't match the required name, then the functionality of the templated control might get broken. To know the parts and their names of TextBox visit TextBox Parts. To know the named parts of all WPF controls visit Control Styles and Templates. This links also contains an example of the actual Style and Template.
An alternative approach to get the required template parts is to select the control you wish to template and then open the XAML designer view. Right click on the selected control and select Edit Template. In the popup select Edit a Copy. A dialog opens. Here you can give the extracted template a name and set the location where the extracted template will be moved to. Now you can edit this template which already has all the required parts.

How to Change the Style on AvalonEdit CodeCompletion Window?

I'm trying to figure out how to change the style of the AvalonEdit CodeCompletion window. However, I can't figure out the right combination of xaml style target/properties to change it. The main thing I'd like to do is get rid of the border, but maybe some additional changes as well.
Here is the xaml I've tried. None of it is affecting the UI.
xmlns:ae="clr-namespace:ICSharpCode.AvalonEdit.CodeCompletion;assembly=ICSharpCode.AvalonEdit"
<Style TargetType="{x:Type ae:CompletionWindow}">
<Setter Property="WindowStyle" Value="None" />
</Style>
<Style TargetType="{x:Type ae:CompletionWindowBase}">
<Setter Property="WindowStyle" Value="None" />
</Style>
<Style TargetType="{x:Type ae:CompletionListBox}">
<Setter Property="Background" Value="Red" />
</Style>
<Style TargetType="{x:Type ae:CompletionList}">
<Setter Property="Background" Value="Orange" />
</Style>
Use this style to remove border on window:
<Style TargetType="{x:Type avalonEdit:CompletionWindow}">
<Setter Property="WindowStyle" Value="None"></Setter>
<Setter Property="ResizeMode" Value="NoResize"></Setter>
<Setter Property="BorderThickness" Value="0"></Setter>
</Style>
To make the styles affect the UI, you can put them in a resource dictionary xaml and parse that with (ResourceDictionary)XamlReader.Parse(ResourcesAsXaml).
Then assign the ResourceDictionary to the Resources property of the CompletionWindow.

TextBlock does not show all text

The problem I have with TextBlock is that it sometimes cuts off text. The image below is the output of the xaml below it. The first TextBlock should contain Défi maximum, but the last m is cut off. I get it to reappear when I change part of the style, but I need it to be exactly like this. What could be the cause of this?
As you can see the TextBlock has enough space, the margin around the TextBlock is blue in the image below. The second TextBlock has an extra character which causes the TextBlock to show the text correctly. (even though there is a spelling error in it ;-) )
<Window.Resources>
<Style TargetType="TextBlock">
<Setter Property="FontFamily" Value="Candara"/>
<Setter Property="FontSize" Value="13"/>
<Setter Property="FontWeight" Value="Regular"/>
<Setter Property="Padding" Value="5"/>
<Setter Property="Background" Value="Red"/>
<Setter Property="TextWrapping" Value="Wrap"/>
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Margin" Value="0"/>
</Style>
<Style TargetType="Grid">
<Setter Property="Width" Value="87"/>
<Setter Property="Height" Value="87"/>
<Setter Property="Background" Value="Blue"/>
<Setter Property="Margin" Value="1"/>
</Style>
</Window.Resources>
<StackPanel Orientation="Horizontal">
<Grid>
<TextBlock>Défi maximum</TextBlock>
</Grid>
<Grid>
<TextBlock>Défi maximume</TextBlock>
</Grid>
<Grid>
<TextBlock>3x10</TextBlock>
</Grid>
<Grid>
<TextBlock>4x10</TextBlock>
</Grid>
</StackPanel>
Decrease the font size or increase the box width.

DatePicker day colors WPF 4

I have the following style for the text block in the dictionary
<Style TargetType="{x:Type TextBlock}">
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Margin" Value="5,0,0,0 "/>
<Setter Property="Foreground" Value="White" />
</Style>
after setting this in the resource dictionary, all the text block i have used in my project have foreground color to white which I have set, now the problem is that the datepicker control when open only shows the selected date, as I have set the foreground color of white for the text block in the above style the date picker control dates are not showing. Please help me as soon as possible as I am stuck in this problem :(
You can use additional style for your DatePicker:
<DatePicker>
<DatePicker.Resources>
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="Black"/>
</Style>
</DatePicker.Resources>
</DatePicker>

Creating a drop shadow style in XAML

I’m struggling a little bit with some XAML syntax I hope someone can advise on. I want to create an “Effect” type style resource which contains a DropShadowEffect definition which can be reused rather than always manually setting the properties. Here’s what I have:
<Style TargetType="DropShadowEffect" x:Name="DropShadowEffectStyle">
<Setter Property="BlurRadius" Value="5" />
<Setter Property="Direction" Value="315" />
<Setter Property="ShadowDepth" Value="2" />
<Setter Property="Opacity" Value="0.5" />
</Style>
<Style TargetType="TextBlock" x:Name="PageTabLabelStyle">
<Setter Property="FontSize" Value="16" />
<Setter Property="FontFamily" Value="Arial" />
<Setter Property="Foreground" Value="#EFEFEF" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Margin" Value="0, 10, 0, 10" />
<Setter Property="Effect" Value="{StaticResource DropShadowEffectStyle}" />
</Style>
This fails dismally each time it runs so I’m obviously missing something. I think it’s around the “Effect” property of the text block style expecting an “Effect” type rather than a “DopShadowEffect” type. Any ideas?
You cannot "style" an effect, because Style is a property of Control and an effect is not a Control.
What you really want to do is put the effect itself into the resource dictionary and use a StaticResource reference to point to it. Something like:
<UserControl.Resources>
<DropShadowEffect x:Key="dropShadow" BlurRadius="25" Direction="315" />
<Style TargetType="TextBlock" x:Name="PageTabLabelStyle">
<Setter Property="FontSize" Value="16" />
<Setter Property="FontFamily" Value="Arial" />
<Setter Property="Foreground" Value="#EFEFEF" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Margin" Value="0, 10, 0, 10" />
<Setter Property="Effect" Value="{StaticResource dropShadow}" />
</Style>
</UserControl.Resources>

Resources