I am binding a TextBLock with a string Property but whenever this Property contains the text "Audit", the actual text displayed on the UI is "Audi". For any other scenario, this works fine.
I am using .Net 4.0 and OS is win XP.
I am not sure if this is a bug but I can't get rid of this. If it is a bug, where do I report WPF bugs? Can anyone else also reproduce this issue? If yes, is there a workaround?
Edit: The Binding for the textblock is:
<TextBlock Padding="0,5,5,5" TextWrapping="Wrap" Text="{Binding TaskRoleMapping}" FontWeight="Bold" Foreground="White" FontFamily="Segoe UI" Margin="3,0,0,0" VerticalAlignment="Center"/>
I am sure it's not a problem with the textlength as much bigger text gets displayed alright.
Edit: The TextBlock is contained in a StackPanel
<StackPanel Height="40" Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Left" Width="Auto">
<ContentControl Content="ContentControl" Template="{DynamicResource vector_Summary}" Height="16"/>
<TextBlock Padding="5,5,0,5" Height="28"
Text="{Binding Path=[LABEL.MAIN.HEADER], Source={x:Static Util:Util.labelDictionary}}"
FontFamily="Segoe UI" FontSize="12"
Foreground="#FFFFFF" Margin="1,7,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="Auto"/>
<TextBlock Padding="0,5,5,5" TextWrapping="Wrap" Text="{Binding TaskRoleMapping}" FontWeight="Bold" Foreground="White" FontFamily="Arial" Margin="3,0,0,0" VerticalAlignment="Center"/>
</StackPanel>
I like Kent Boogaart's comment/points. Basically 't' char is being cut off/out from the view. So change the font size to smaller, or remove "Bold" or introduce min size of the TextBlock, or it's parent and 't' in "Audi" will magically appear
Related
I want to add two TextBlocks in one column of my WPF project. I use the following codes but They locate on eachother now. How may I insert them after each other (not on each other)? Please note that I don't want to put them in two seperate columns.
<TextBlock Grid.Row="6" Grid.Column="1" x:Name="FirstName" Margin="10,10,0,0"/>
<TextBlock Grid.Row="6" Grid.Column="1" x:Name="LastName" Margin="10,10,0,0" Grid.ColumnSpan="2"/>
You can use a WrapPanel to host the TextBlocks horizontally:
<WrapPanel Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="2">
<TextBlock x:Name="FirstName" Margin="10,10,0,0" Text="FirstName" />
<TextBlock x:Name="LastName" Margin="10,10,0,0" Text="LastName" />
</WrapPanel>
I need to know the height of a wrapped textBox. I am using this code:
MyView myView = new MyView();
myView.MyTextBox.Text = "my large text";
myView.UpdateLayout();
double myHeight = myView.MyTextBox.Actualheight;
No matter how large is the text, I always get 12.96 as actualheight.
If I do the same with a datagrid in which I am add new items, I am getting the right height, so I am wondering if sometimes a wrapped textbox has another behavior.
Thanks.
EDIT: i have realized that the size depends of the size of the font. At first I setted 8, but if I set 16, the actual height is the double too. So it seems that the height of the textBox depends of the font size, and it has not account if it is wrapped or not.
Running a simple test in XAML, when the text wraps, it causes the textbox ActualHeight to increase as expected as shown in the image below.
<StackPanel Orientation="Horizontal">
<TextBox Width="100" HorizontalAlignment="Left" Margin="10"
FontSize="10" Name="tbx1"
TextWrapping="Wrap" Text="Some short text"/>
<TextBlock Foreground="White" VerticalAlignment="Center"
FontSize="20"
Text="{Binding ActualHeight, ElementName=tbx1, Mode=OneWay}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBox Width="100" HorizontalAlignment="Left" Margin="10"
FontSize="10" Name="tbx2"
TextWrapping="Wrap" Text="Some text that is longer"/>
<TextBlock Foreground="White" VerticalAlignment="Center"
FontSize="20"
Text="{Binding ActualHeight, ElementName=tbx2, Mode=OneWay}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBox Width="100" HorizontalAlignment="Left" Margin="10"
FontSize="15" Name="tbx3"
TextWrapping="Wrap" Text="Short text"/>
<TextBlock Foreground="White" VerticalAlignment="Center"
FontSize="20"
Text="{Binding ActualHeight, ElementName=tbx3, Mode=OneWay}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBox Width="100" HorizontalAlignment="Left" Margin="10"
FontSize="15" Name="tbx4"
TextWrapping="Wrap" Text="Some text that is longer"/>
<TextBlock Foreground="White" VerticalAlignment="Center"
FontSize="20"
Text="{Binding ActualHeight, ElementName=tbx4, Mode=OneWay}" />
</StackPanel>
UpdateLayout doesn't actually cause anything to be rendered, it just prepares it. So until you render your view or window with myView.Show() or something equivalent, the textbox doesn't get rendered so the ActualHeight value doesn't get calculated.
Again am stuck to change the background color of my text box but the weird part is forground is works fine but not the background.
Here is my xaml
<TextBox
Name="tbHeadline"
Text="{Binding SelectedStory.Headline, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{StaticResource ErrorTemplate}"
Grid.Column="1"
Grid.Row="6"
TextWrapping="NoWrap"
d:LayoutOverrides="Height"
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
LostFocus="tbHeadline_LostFocus"
/>
in my Xaml.cs
I have the following code
tbHeadline.Background = Brushes.Gray; //this not working
tbHeadline.Foreground = Brushes.Gray; //this is working
here is the sample output
Thanks for your help.
Update from the expert comments
Okie, i added a textbox in the grid and this what it look like
<TextBox Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="10" Grid.RowSpan="2" Height="23" HorizontalAlignment="Left" Margin="50,14,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" Background="#E6000000" />
Even i set the background color to Black but its not visible when i run the application.
In summarizing our discussion in Chat, you have a Default Style that is overriding your TextBox's Background Brush. I suggested that you set your TextBox's Default Style to Null as the answer to this SO question suggests. You can do this in either the Code Behind or in the Xaml declaration of your TextBox.
tbHeadline.Style = null;
or in your Xaml
<TextBox Name="tbHeadline" Style=""
Text="{Binding SelectedStory.Headline, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"
Validation.ErrorTemplate="{StaticResource ErrorTemplate}"
Grid.Column="1"
Grid.Row="6"
TextWrapping="NoWrap"
d:LayoutOverrides="Height"
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
LostFocus="tbHeadline_LostFocus" />
Your code snippet should work. You can test by creating a blank project, dropping a TextBox and setting the colors in code. Use Snoop to see if tb's background is being set in different ways or different places.
Your code snippet should work. Just set style to null like this
<TextBox Style ={x:Null} Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="10" Grid.RowSpan="2" Height="23" HorizontalAlignment="Left" Margin="50,14,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" Background="#E6000000" />
Try tbHeadline.Background = new SolidColorBrush(Colors.Gray);
This is my original code:
<StackPanel Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal">
<ProgressBar Height="23" Name="searchProgressBar" Foreground="Blue" BorderBrush="#00000000" BorderThickness="1" VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
<TextBlock Text="asdf" Height="23" Name="progressTextBlock" VerticalAlignment="Top" Foreground="Red" HorizontalAlignment="Right"/>
</StackPanel>
The progressbar was very small, maybe 2 or 3 pixels wide, then there was the text block and empty space after. So I tried explicitly docking the elements to sides:
<DockPanel Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" >
<ProgressBar DockPanel.Dock="Left" Height="23" Name="searchProgressBar" Foreground="Blue" BorderBrush="#00000000" BorderThickness="1" VerticalAlignment="Top" />
<TextBlock DockPanel.Dock="Right" Text="asdf" Height="23" Name="progressTextBlock" VerticalAlignment="Top" Foreground="Red" HorizontalAlignment="Right"/>
</DockPanel>
No avail. I also tried modifying each solution by setting HorizontalAlignment="Stretch" on the progress bar, but there's no change. How do i stretch it to fill all the space there is after the text block has been rendered?
Remove DockPanel.Dock="Left" from the ProgressBar and switch the order of the controls:
<DockPanel>
<TextBlock DockPanel.Dock="Right" Height="23" VerticalAlignment="Top" HorizontalAlignment="Right"/>
<ProgressBar Height="23" VerticalAlignment="Top" />
</DockPanel>
By default, DockPanel has its property LastChildFill set to true, which will make the ProgressBar take the available space.
ahh I see what you're trying to do. This is probably a better place to use a grid with 2 column definitions. The first(the left one) columndefinition with Width="*" and the second(the right one) with a width set to Width="Auto". For more info about auto vs * see http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/9a7e6591-1fae-4295-b68a-be97e8e53d06/
Hi
I have to add support for other languages in my application. Almost entire application is ready however I have a problem with translating a tooltip which is 'loaded' from resourcesDictioanry file.
For couple element in my application I have the same tooltip. So instead of writting the same code over and over again I decied to put a tooltip into ResourceDitionary.
My tooltip looks like that
<TextBlock FontWeight="Bold" Text="Text to translation" TextAlignment="Left" />
<TextBlock Text="{Binding Path=_Code}" Grid.Column="1" TextWrapping="Wrap"/>
<TextBlock FontWeight="Bold" Text="Text to translation" TextAlignment="Left" Grid.Row="1" />
<TextBlock Text="{Binding Path=_Name}" Grid.Column="1" Grid.Row="1" TextWrapping="Wrap"/>
<TextBlock Text="Text to translation:" Grid.Row="3" FontWeight="Bold" TextAlignment="Left" />
</Grid>
</ToolTip>
What is the best way to implement multilanguage support from ResourcesDictionary ?
You should perhaps substitute
Text="Text to translation"
by
Text="{DynamicResource TOOLTIP_TEXT_ID}"
This recipy assumes your application's translation is resource dictionary-based, of course.