WPF/XAML: Typography.Capitals seems to have no effect - wpf

All of these bits of text look the same, but I am trying to get them to look different. I want small caps text. What am I missing here to get the small caps typography effect to work?
To reproduce this, open Visual Studio 2008, Do File|New Project, create a new Windows|WPF application, paste the mark-up below into Window1.xaml, then run it.
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<FlowDocumentReader>
<FlowDocument>
<Paragraph>
<Run>Some text</Run> <LineBreak />
<Run Typography.Capitals="SmallCaps">Some text</Run> <LineBreak />
<Run Typography.Capitals="AllSmallCaps">Some text</Run> <LineBreak />
<Run Typography.Capitals="PetiteCaps">Some text</Run> <LineBreak />
<Run Typography.Capitals="AllPetiteCaps">Some text</Run> <LineBreak />
</Paragraph>
</FlowDocument>
</FlowDocumentReader>
</Grid>
</Window>
Based on the first answer, it seems that if you specify a particular font, you can get somewhere. Change the FlowDocument start tag to:
<FlowDocument FontFamily="Palatino Linotype">
.. and you get SmallCaps and AllSmallCaps, but not PetiteCaps or AllPetiteCaps. So it depends on the font. But this gives rise to other questions:
Why doesn't the default font (which looks a lot like Times New Roman) support these?
Do other widely used fonts (e.g. the local Courier New equivalent) support these?
Is there a list of which fonts support what?
What percentage of fonts will support this - most, some, or few?
Can you determine in code what the font supports - if this is the case, I could fake the AllSmallCaps - e.g. by converting the text to all capitals and scaling by 80%. But not SmallCaps.

This only works with specific OpenType fonts - the example in Help uses Pescadero which is in the Open Type Sample. Even then, only SmallCaps and AllSmallCaps are supported.

I noticed that default font with a "bold" fontweight does render the SmallCaps properly:
<StackPanel>
<TextBlock Typography.Capitals="SmallCaps" FontFamily="Pescadero" Padding="2">2pm</TextBlock>
<TextBlock Typography.Capitals="SmallCaps" FontWeight="Bold" Padding="2">2pm</TextBlock>
</StackPanel>

Related

How to start using Ribbons in WPF

I tried referencing the System.Windows.Controls.Ribbon, the toolbox tab does not show up. If I right-click a tab and click show all, the tab is there, but controls aren't light up. I can add a tab and controls related manually, but after adding the ribbon, things like quickaccesstoolbar and menuitem does not work properly - they are being treated as tabs for some reason. Control groups don't work as well. Simply nothing works as it's supposed to.
I have tried editing XAML directly. It fails in the same manner as using the designer.
The tutorials online are either outdated, for a paid control suite, or simply don't work.
I don't want to use mark-up solutions like http://www.codeproject.com/Articles/364272/Easily-Add-a-Ribbon-into-a-WinForms-Application-Cs , I want something that works in a designer -- Is that too much to ask? If so I'll gladly go back to winforms.
If you work with ribbons, how did you do it? This question seems simple, but after digging for hours I still don't have an answer.
I'm an individual developer, making an open source, free software. As a student I really can't afford 1000$ control suites. I use VS2013 community, I tried using 2015 instead, but all the problems above are the same.
Add this reference:
and this namespace in the XAML file:
and try working with this code example:
<DockPanel>
<Ribbon DockPanel.Dock="Top" Margin="0,-22,0,0">
<Ribbon.ApplicationMenu>
<RibbonApplicationMenu SmallImageSource="Images/list.png">
<RibbonApplicationMenu.AuxiliaryPaneContent>
<RibbonGallery ScrollViewer.VerticalScrollBarVisibility="Auto">
<RibbonGalleryCategory MaxColumnCount="1">
<RibbonGalleryItem
x:Name="GalleryItem1" Content="Application menu content"
MouseOverBackground="Transparent"
MouseOverBorderBrush="Transparent"
CheckedBackground="Transparent"
CheckedBorderBrush="Transparent"
/>
<RibbonGalleryItem>
<Hyperlink x:Name="hl1" Click="hl1_Click">
<Run Text="http://www.bing.com"/>
</Hyperlink>
</RibbonGalleryItem>
</RibbonGalleryCategory>
</RibbonGallery>
</RibbonApplicationMenu.AuxiliaryPaneContent>
<RibbonApplicationMenuItem x:Name="menuItem1" Header="Add"
ImageSource="Images/add.png"/>
<RibbonApplicationMenuItem x:Name="menuItem2" Header="Settings"
ImageSource="Images/system_preferences.png"/>
<RibbonApplicationMenu>
</Ribbon.ApplicationMenu>
<RibbonTab x:Name="rbnTab1" Header="Tab1">
<RibbonGroup x:Name="rbnGr1" Header="General">
<RibbonButton x:Name="btnRibbon1" Label="Save"
LargeImageSource="Images/filesave.png"/>
<RibbonButton x:Name="btnRibbon2" Label="Open"
LargeImageSource="Images/load.png"/>
</RibbonGroup>
<RibbonGroup x:Name="rbnGr2" Header="New group">
<RibbonButton x:Name="btnRibbon3" Label="Font"
LargeImageSource="Images/fonts.png"/>
<RibbonButton x:Name="btnRibbon4" Label="Delete"
LargeImageSource="Images/recycle_bin.png"/>
</RibbonGroup>
</RibbonTab>
<RibbonTab x:Name="rbnTab2" Header="Tab2">
<RibbonGroup x:Name="rbnGr3" Header="Other Group">
<RibbonButton x:Name="btnRibbon5" Label="Play"
LargeImageSource="Images/play.png"/>
<RibbonButton x:Name="btnRibbon6" Label="List"
LargeImageSource="Images/kmenuedit.png"/>
</RibbonGroup>
<RibbonGroup x:Name="rbnGr4" Header="What a group">
<RibbonButton x:Name="btnRibbon7" Label="Sleep"
LargeImageSource="Images/icon_sleep.png"/>
<RibbonButton x:Name="btnRibbon8" Label="Add"
LargeImageSource="Images/add.png"/>
</RibbonGroup>
</RibbonTab>
</Ribbon>
<Grid>
<!-- add your content here-->
</Grid>
</DockPanel>
You can remove the <Ribbon.ApplicationMenu> if you don't like it by addin this property Visibility="Collapsed"
<Ribbon.ApplicationMenu>
<RibbonApplicationMenu Visibility="Collapsed">
</RibbonApplicationMenu>
</Ribbon.ApplicationMenu>
Please take a look at the following. You should be able to have a very basic idea about Ribbon.
http://blogs.msdn.com/b/wpf/archive/2010/08/03/introducing-microsoft-ribbon-for-wpf.aspx
Sample project download
If you want to run the project, you need to change the project's .NET Framework version to 4.0 or above.
Add System.Window.Controls.Ribbon reference to the project
Remove reference like System.Window.Shell and RibbonControlLibrary
The sample should be able to run after you fixed all the namespaces in xmal and the codebehind .cs
http://blogs.msdn.com/b/wpf/archive/2010/08/03/building-a-simple-ribbon-application-in-wpf.aspx
Microsoft Ribbon for WPF (Get the one with Sample for more comprehensive sample)
http://www.microsoft.com/en-us/download/details.aspx?id=11877

Inline Run objects not completely highlighted when a hyphen is present

I've got this really weird problem where I'm doing highlighting on certain parts of text on a TextBlock object containing multiple Run objects.
<TextBlock Name="InlineTextBlock" Background="White">
<Run Foreground="White"
Background="Blue"
FontSize="75"
FontFamily="Helvetica">17-Oct-13</Run>
<Run Foreground="White"
Background="Blue"
FontSize="75"
FontFamily="Helvetica">17/Oct/13</Run>
</TextBlock>
It's pretty straightforward code to read, and from reading, you would expect both 17-Oct-13 and 17/Oct/13 to be completely highlighted with a Blue Background and White Foreground.
The odd thing is, the hyphen character has 1 pixel on the left and the right where the Background color is not being applied.
There are no issues with highlighting for the second Run object with 17/Oct/13.
Would appreciate any help to figure out this odd problem.
EDIT:
Running this on my computer displays the following (you'll have to look really closely to see it):
Also, I noticed this only occurs on certain fonts like Helvetica, Arial, Consolas (to name a few). Verdana seems to display fine.
Unfortunately, running your code on my computer does not suffer from this problem:
I'm guessing that you have something else causing your problem.
For your information, I'm running Visual Studio 2010 on Windows 7 and .NET 4.0.
UPDATE >>>
Thanks for the update... I can now confirm that I see your mysterious vertical white lines around the hyphens using the Helvetica font. I can't imagine what is causing it, but assuming that you can't set the main TextBlock.Background to Blue, you can still fix this issue by using an inner TextBlock with its Background set to Blue:
<TextBlock Name="InlineTextBlock" Background="White">
<TextBlock Background="Blue">
<Run Foreground="White"
Background="Blue"
FontSize="50"
FontFamily="Helvetica">17-Oct-13</Run>
<Run Foreground="White"
Background="Blue"
FontSize="50"
FontFamily="Helvetica">17/Oct/13</Run>
</TextBlock>
</TextBlock>

WPF: XamlWriter.Save saves "Run" inlines differently - with tags and without (as simple text)

Textblock have 3 run inlines. I need to save it to xml, and I use XamlWriter.Save for that, as the result I got this:
<TextBlock xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
FontSize="14" FontFamily="Georgia" >
ABC
<Run FontSize="13">DEF</Run>
GHI
</TextBlock>
The problem is, that this xaml is parsed then as a pure xml without using wpf framework. To make the parser work correctly I have to ensure, that xaml is presented like this:
<TextBlock xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
FontSize="14" FontFamily="Georgia" >
<Run>ABC</Run>
<Run FontSize="13">DEF</Run>
<Run>GHI</Run>
</TextBlock>
e.g. every inline is a separate tag. How can I do this?
I looked through properties and settings of XamlWriter and Inlines collection, but couldn't find anything that corresponds to that.

How to center text around point using xaml

I would like to be able to place the word "hello" centered on a specific point. I need to do this completely in XAML without extra code. Best I can tell, all the text alignment properties/styles in XAML act on text within some bounding canvas or other element.
Since I don't know the length of the text I want to center, I can't center it using my own code.
The reason I need to solve the problem entirely in XAML is that I'm not using WPF to create the XAML, I'm writing it directly to an XML DOM. It will then be loaded into a Silverlight or WPF control for display.
In most graphic languages, including SVG, which is where my code originated, text can be aligned against a "stationary point" without a bounding box.
Any suggestions appreciated
(Yes, I know this question is old.)
The effectiveness of this solution may vary with the version of Silverlight or the .NET Framework you are using, and I haven't tried it with Silverlight for Windows Phone 7. I wrote a version for stand-alone WPF applications, and I wrote another version that also works in Silverlight.
First, the version that works in Silverlight and WPF. Please note that you will need to refactor the code a little bit if you aren't using a Canvas to provide an absolute position for the center of your TextBlock. For example, you may be using a TranslateTransform to position your text.
<Canvas>
<Canvas.Resources>
<ScaleTransform x:Key="transform" ScaleX="-1" ScaleY="-1" />
</Canvas.Resources>
<Grid RenderTransform="{StaticResource transform}" RenderTransformOrigin="-.25 -.25">
<TextBlock RenderTransform="{StaticResource transform}">
Hello!
</TextBlock>
</Grid>
</Canvas>
Second, the version that works only in WPF. It doesn't work in Silverlight because it depends on the presence of the Canvas.Right and Canvas.Bottom attached properties. UniformGrid isn't in Silverlight either, but that code could have been replaced by a regular Grid with 2 star-length rows and columns.
<Canvas>
<UniformGrid Rows="2" Columns="2"
DataContext="{Binding ElementName=textBox1}"
Width="{Binding Path=ActualWidth}"
Height="{Binding Path=ActualHeight}">
<Canvas>
<TextBlock Name="textBox1" Canvas.Right="0" Canvas.Bottom="0">
Hello!
</TextBlock>
</Canvas>
</UniformGrid>
</Canvas>
By the way, there may be more efficient ways to solve this problem available. I am making no guarantees!

WPF RichTextBox - spell check does not work with formatted text

If I define a RichTextBox as follows;
<RichTextBox SpellCheck.IsEnabled="True">
<FlowDocument />
</RichTextBox>
When I type in the work 'Sample' and make the first three letters bold, the spell checker underlines the word.
The source XAML of the document shows that the RichTextBox is splitting the word into two seperate runs;
<Paragraph>
<Run FontWeight="Bold" xml:lang="en-gb">Sam</Run>
<Run xml:lang="en-gb">ple</Run>
</Paragraph>
If I manually contruct a document with the following blocks;
<FlowDocument>
<Paragraph>
<Run FontWeight="Bold">Sam</Run>ple
</Paragraph>
</FlowDocument>
The spell checker passed the word successfully.
Has anyone come across this before? Is there a workaround that I can use?
Thanks
Matt
There seem to be issues with the spell checker and different locales.
If I start with this:
<RichTextBox SpellCheck.IsEnabled="True" xml:lang="en-GB">
<FlowDocument />
</RichTextBox>
I can reproduce your error (by typing "Sample" and bolding the "Sam"), but not with this:
<RichTextBox SpellCheck.IsEnabled="True">
<FlowDocument />
</RichTextBox>
Someone has a similar problem here. Microsoft replies:
This problem occurs because the Language property on FrameworkElement (and thus TextBox/RichTextBox) defaults to "en-US", and you are using the "en-NZ" locale. When you type text into TextBox/RichTextBox, it will be in a different locale than the text set in XAML. The spell checker does not cross language boundaries, which results in the behavior you see.

Resources