Textblock displaying "..." instead of "-" when Width="Auto" - wpf

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.

Related

Is there a mathematical formula that can be applied to determine margin and (possibly) font size

In a wpf user control I'm creating the end user has the option to alter the default size of the included images. When Originally designing the control I based my eventual margin sizes on trial and error, eventually settling on what looked right to me.
When image sizes were either 16 x 16 or 24 x 24 the overall look is reasonable;
but once you start to dramatically increase the image size to two textboxes and text block in the control get thrown out of sync with the images.
The xaml that I originally used for the text and text block is shown below (it also includes the find button in the middle of them but helps by showing how all buttons are defined).
<TextBox x:Name="Record" BorderThickness="0" Margin="6" ></TextBox>
<Button Background="#00000000" x:Name="Find" Height="Auto" Width="Auto"
ToolTip="Find the Record at this position." BorderThickness="0">
<StackPanel Margin="2" Orientation="Horizontal">
<Image Source="{Binding ImageFind, ElementName=DN}"
Width="{Binding ImageFindWidth, ElementName=DN}"
Height="{Binding ImageFindHeight, ElementName=DN}"/>
<TextBlock Margin="3" Text="{Binding TextFind,ElementName=DN}"/>
</StackPanel>
</Button>
<TextBlock Margin="6">of</TextBlock>
<TextBox x:Name="Records" BorderThickness="0"
Margin="6"
Text="{Binding RecordsCount, ElementName=DN}"></TextBox>
All of the buttons and text boxes are contained in a stack panel with horizontal orientation set.
What I would like to know if is there is a mathematical formula that I could apply to the textboxes and textblock at the time that the end user changes the width height of the images (they will always be the same in either dimension) that would correct the layout , thus centring the text in line with the middle of the images.
Possibly there is some other wpf layout trick about which I have yet to learn that does this sort of thing, either way I'd welcome suggestions.
Thanks
Set the VerticalAlignment property on the TextBlock and VerticalContentAlignment on the TextBox.
<TextBlock Margin="6" VerticalAlignment='Center'>of</TextBlock>

My rowSpan doesn't take 2 lines

I got a weird problem with the rowSpan property of a grid.
I got a text that will take more than one line, so I told his stack spanel, RowSpan="2", so the text can be on multiple line, using Wrapping to, like this :
<StackPanel Grid.Row="0"
Grid.RowSpan="2"
Orientation="Horizontal">
<TextBlock x:Name="tbConfirm"
Text={Binding TextConfirm}
HorizontalAlignment="Center"
TextWrapping="Wrap"
VerticalAlignment="Center"
Grid.RowSpan="2"
FontSize="12">
</TextBlock>
</StackPanel>
The property TextConfirm contains a text that should take two lines (I tried with the text without binding to see if it fills.
But, despite my RowSpan and my TextWrapping, it still on one line, and don't understand why.
When I make a column span, it will take the number of column define, but why row span doesn't work?
There is in the Grid, 5 column(width auto) and 5 row(height auto) define.
If I want to have one textblock, one textbox, and another one textblock.
How can I tell to go in the new line automatically?
Undefined width for the two textblocks, and define width for the textbox.
This is just an example, I don't wrote it at the moment.
<StackPanel Grid.Row="0"
Grid.RowSpan="2"
Orientation="Horizontal">
<TextBlock x:Name="tbConfirm"
Text={Binding TextConfirm}
HorizontalAlignment="Center"
TextWrapping="Wrap"
VerticalAlignment="Center"
Grid.RowSpan="2"
FontSize="12">
</TextBlock>
<textBox width ="200"/>
<TextBlock x:Name="tbConfirm2"
Text={Binding TextConfirm2}
HorizontalAlignment="Center"
TextWrapping="Wrap"
VerticalAlignment="Center"
Grid.RowSpan="2"
FontSize="12">
</TextBlock>
</StackPanel>
Will this, go automatically at the new line if necessary? Or do I need to define lines and colums in the xaml?
Thank you.
I'm not sure if i understand the question correctly but to get the text wrapping you don't need to span accross multiple rows. From what i've read you have set the column width to auto so it will let the TextBlock "grow" freely. If you want to get the wrapping working you should define a fixed width either on the column or on the TextBlock itself (and keep the TextWrapping="Wrap").
try binding the width of the textblock to that of the parent as you wont want it to exceed that
<TextBlock x:Name="tbConfirm"
Text="asasddadsa adassdasd asdasdasdsa asdasdssd asdasdasjdahsjakdhksajdhjsaalskasj skjdsajkdhajhasaskjhdsahsakdasjdhsajdhasjdhkjsad"
HorizontalAlignment="Center"
Foreground="Black"
Width="{Binding ActualWidth, ElementName=stackPanelParent}"
TextWrapping="Wrap"
VerticalAlignment="Center"
FontSize="12">
</TextBlock>
I gave my own content to test. In case it overflows let me know.

StackPanel Orientation in xaml

I got a weird problem on my xaml, in a stackPanel.
My stackPanel contains a textbox, and a button.
This should be on the same line (if possible, depending on the text width).
The problem is :
if the stackPanel have Orientation="Vertical", the button will go to the line bellow the text.
if the stackPanel have Orientation="Horizontal" , the line will not doing any break line, so all the line will go out of my grid.
<StackPanel Name="spRemplir"
Grid.Row="2"
Grid.ColumnSpan="6"
Width="560"
Margin="5,5,5,5"
Orientation="Horizontal"
VerticalAlignment="Center">
<TextBlock FontWeight="Bold"
Text={Binding Text}
TextWrapping="Wrap"/>
<Button Name="btRemplir"
Margin="5,0,0,0"
Width="150"
Content="Remplir"/>
</StackPanel>
How can I obtain a stackPanel, that will break lines if necessary, and have a text and a button on the same line?
Update with Wrapanel thanks to Eli Arbel :
<toolkit:WrapPanel Name="spRemplir"
Grid.Row="2"
Grid.ColumnSpan="6"
Margin="5,5,5,5"
Width="560"
Orientation="Horizontal">
<TextBlock FontWeight="Bold"
Text={Binding Text}
TextWrapping="Wrap"/>
<Button Name="btRemplir"
Content="Remplir"/>
</toolkit:WrapPanel>
But, the button still on the next line, while there is enough space after the text on the same line.
Itried removing the Width on the panel, but then, there is no more wrapping...
I don't understand. Even if there is stackPanel on the same Grid, they should not disturb the wrap panel right?
Thank you.
You can try a WrapPanel from the Silverlight Toolkit. Note this panel will not allow you to stretch the items to the container width.
You should also look into removing the fixed Width of the panel.
Try using a Grid instead of a StackPanel. The problem with StackPanel is that they do not report up the Visual Tree that they are out of room. This is not a bug, it's just the way they are and it's appropriate when you need it. But I avoid them except on the innermost elements. But don't have StackPanels in StackPanels as you will lose TextWrapping/Scrolling and just have elements fall of the right or bottom of the page.
Second, make sure that your outer container is Set so that the width is Constrained. For example, in your layout root, give it one Column, and set the Width for * which means = "The available space, but not more"
Once you have your outer container constrained, then your TextBlock will wrap properly.
Greg
Consider using a WrapPanel instead stack panel: http://wpftutorial.net/WrapPanel.html

Pixellated and Broken Text on WPF Animation

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.

wpf: making textblock height expand when text gets too big for 1 line

I have a listview with an itemtemplate:
<ListView x:Name="messages" HorizontalAlignment="Left"
Background="{x:Null}" BorderBrush="{x:Null}" Foreground="Black">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Style="{DynamicResource h3}" Text="{Binding}"
Margin="10" MaxWidth="850"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
This listview is in a vertical stackpanel. So its width is the same as the stackpanel's width.
The listview must show messages that could be very long. I'm trying to make sure that when a message is too long for the available width, the textblock gets extra height and the text gets displayed on 2 lines.
I can google a lot of ways to have this achieved with a fixed height, but since I don't know in advance if I'll need more than 1 line, I'd like to make sure it happens automaticly.
I don't want every item to have the height of 2 lines, only when it's needed.
How can I achieve this?
Have you tried the TextWrapping property? It seems that it would do what you want.

Resources