I have a control with an animation applied on the Height property. The control contains a ListBox with TextBlock as ListItem. But the text is blurred, broken, or pixellated during animation. Below please see the images during different points in the animation.
The code of my TextBlock:
<TextBlock x:Name="Description"
Padding="0,2,0,2"
Grid.Column="1"
TextOptions.TextRenderingMode="ClearType"
HorizontalAlignment="Left" VerticalAlignment="Center"
Text="{Binding Description}"
ToolTip="{Binding Description}"
TextTrimming="CharacterEllipsis"
Foreground="White"
FontSize="11" FontFamily="{DynamicResource StandardFontType}"/>
I tried all different options for TextOptions.TextRenderingMode and DisplayModes from this link, but nothing could solve my problem.
Try switching between:
TextOptions.TextFormattingMode="Ideal"
and
TextOptions.TextFormattingMode="Display"
Also please note that Borders with shadows can cause trouble with Text rendering, see this SO link
As described in that link, you can have the best of both worlds (the shadows + the nicely rendered text) by using a Grid and putting both elements in the same Row/Column: they are therefore superimposed but the text won't suffer from the shadow.
Related
In a StackPanel, I would like the Height of the TextBlock to dictate the height of the Image, but trying to bind the Image Height to the TextBlock ActualHeight causes the Image to disappear. The height of the TextBlock will vary depending on the size of the font being used.
The StackPanel is defined as follows:
<StackPanel Orientation="Horizontal">
<Image Source="{Binding HyperlinkIconImagePath}"
Height="{Binding ElementName=hyperlinkTextBlock, Path=ActualHeight}"
Margin="{StaticResource IconLeftMargin}"
VerticalAlignment="Center"/>
<TextBlock>
<Hyperlink
NavigateUri="{Binding HyperlinkUri}">
<TextBlock
Name="hyperlinkTextBlock"
Text="{Binding HyperlinkDisplayedText}"/>
</Hyperlink>
</TextBlock>
</StackPanel>
I have tried many different things and none will work. Any help is greatly appreciated. Note that this StackPanel is contained in a ControlTemplate.
The solution to this issue came from a rather subtle direction. I was initially trying to bind to the ActualHeight value of the TextBlock. During the layout process, the ActualHeight value was apparently not yet determined when it was referenced by the Image Height attribute. I then thought about using the size of the font being displayed in the TextBlock, and this FontSize value apparently is already established and usable.
<Image Source="{Binding HyperlinkIconImagePath}"
Height="{Binding ElementName=HyperlinkTextBlock, Path=FontSize}"
Margin="{StaticResource IconLeftMargin}"
VerticalAlignment="Center"/>
I therefore changed the Image Height binding to reference the TextBlock font size, and this resulted in a successful rendering.
try VerticalAlignment="Center" :
<TextBloc VerticalAlignment="Center" .../>
If I put the Column where the toolbar is hosted to be very big (800) then all the text is visible:
but if I put a smaller column this happens:
But I cannot understand why:
<DataTemplate x:Key="IconFilterButton">
<StackPanel Orientation="Horizontal">
<TextBlock
VerticalAlignment="Center"
Style="{StaticResource LargeIconStyle}"
Text="{Binding}" />
<TextBlock
Margin="6,0,0,0"
VerticalAlignment="Center"
DataContext="{Binding}"
Style="{StaticResource BodyTextStyle}"
Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ToggleButton}, Path=Tag}" />
</StackPanel>
</DataTemplate>
and here the definition
<ToggleButton
x:Name="DFilter"
Click="Filtering_Click"
Content=""
ContentTemplate="{StaticResource IconFilterButton}"
Tag="1d"
/>
<ToggleButton
x:Name="WFilter"
Click="Filtering_Click"
Content=""
ContentTemplate="{StaticResource IconFilterButton}"
Tag="1w"
/>
Even worst if I click on the button once they are out:
and then the text is visible but is wrong as the TextBlock is not considered in the object size:
The WPF ToolBar control uses a custom panel for the overflow Popup. In many styles, the ToolBarOverFlowPanel has a property WrapWidth set to a static value like 200. This determines how many items can be displayed before it wraps to another row in the popup.
I've created custom styling for this control and have found that the ToolBarOverFlowPanel used internally is buggy. That's probably the source of your problem.
You can re-template the ToolBar and wire-up a different value for WrapWidth to try to fix the issue, but my guess is that you'll still run into layout problems.
Otherwise, you might consider making your own replacement control.
I have a Textblock that shows 3 Dots instead of a Minus when Width is set to Auto. The Font is Arial and the FontSize is 20. The Width during Runtime is 7.
<:TextBlock
x:Name="LabelText"
MaxHeight="50"
TextTrimming="CharacterEllipsis"
TextWrapping="Wrap"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Grid.Column="1"
Margin="5,0,0,0"
Style="{StaticResource TextLabelFontStyle}"
Width="Auto" />
Anyone know why i dont see the Minus?
#Bulli, what nit was saying in his comment is that those 3 dots are added to the end of a TextBlock when the text does not completely fit into the allowed space when you use a TextTrimming value of CharacterEllipsis.
So you have two possible solutions... the first is to follow nit's advice and remove that property from your TextBlock. As you said that you don't want to do that, the only other option is to make your TextBlock wider so that the text will fit inside.
This must be some strange TextBlock behaviour. I changed the HorizontalAlignment="Left" to HorizontalAlignment="Stretch" and added TextAlignment="Left". Now it wokrks properly.
I'm displaying a series of messages (like emails) on a Grid:
<layout:TransitioningContentControl Name="tccCmdMessage" Margin="0,4">
<layout:TransitioningContentControl.ContentTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Title}" FontWeight="SemiBold" />
<TextBlock Name="tbCmdMessage" Text="{Binding Message}" TextTrimming="WordEllipsis" />
</StackPanel>
</DataTemplate>
</layout:TransitioningContentControl.ContentTemplate>
</layout:TransitioningContentControl>
However, the tbCmdMessage never displays. If I remove the TextTrimming (or change it to None) it works. Alternatively if I don't use a ContentControl parent it also works.
Any ideas?
Take a look at this link: http://social.msdn.microsoft.com/Forums/eu/wpf/thread/30fd3279-7bc8-424f-9ee6-41b9f9589a1a.
I suppose explicitly specifying the Width (or MaxWidth) of the StackPanel can make the texts trimmed. You can also try to use another type of container, like Grid.
Other links with similar issue described:
Silverlight text trimming and wrapping issue
TextTrimming not working
http://forums.silverlight.net/t/58227.aspx/1
Currently I'm using a TextBlock to show a single line with an image.
<TextBlock>
<Image Name="StatusImage" Stretch="Fill" MaxWidth="12" MaxHeight="12"
Source="/Aam.Cerberus.Applications;component/Images/Warning.png"></Image>
<TextBlock Text="{Binding Path=ServiceStatusText}"></TextBlock>
<TextBlock Text=" ("></TextBlock>
<TextBlock Text="{Binding Path=ServiceMachineName}"></TextBlock>
<TextBlock Text=")"></TextBlock>
</TextBlock>
My questions are:
Is a TextBlock the right way to do this sort of thing?
How do I enable word wrapping?
You want the TextWrapping="Wrap" property.
However, according to the MSDN
TextBlock is not optimized for scenarios that need to display more than a few lines of content; for such scenarios, a FlowDocument coupled with an appropriate viewing control is a better choice than TextBlock, in terms of performance.