.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Post New Web Links

Possible bug with TextBlock TextTrimming?

Posted By:      Posted Date: October 04, 2010    Points: 0   Category :WPF

I have used the following markup in a WPF application main window:




Window x:

View Complete Post

More Related Resource Links

image and TextBlock docking WPF application

Hello, I'm new with WPF and I'm struggling here with docking a TextBlock and Image. I've an image that i want to use as a background to my window, the image contains picture and text, and i want to add a TextBlock above the image text, i've no problem doing it, but when i change my window size (press the maximize button) the space between the image and the textblock is not saved, what should i do in order to save my look&fell when the window resizes? i tried using DockPanel, and any other panel, but i guess i'm doing something wrong, so i will really appreciate an example.   Thanks a lot for helping, Gidi.

Textblock and left/top alignment has different space

Hi, when i add a text the text is aligned left,top by default. At the left the text hits the edge, but at the top the text still has space left. Is this because of some special characters that need that space? I would like to show the text with left and top the same amount of space. <Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <TextBlock Background="Red" FontSize="100" FontFamily="Verdana" Padding="0" >T98}`|_*dfshjd sjlksdj dsjl djskldj lksj dlksj</TextBlock> </Grid> </Window>

WPF: How add check mark to the textblock?

I am wondering if anyone knows the tag for check mark symbol. I need to have it in a texblock. I looked online for any clue and did not find anything that will work with XAML. Thank you in advance.

WPF: Adding checkbox with content Textblock at dynamically - width width returns NaN

I want to add set of checkbox at runtime one by one in one column. So i am creating check box object with content Textblock (Textwrapping = wrap) and adding to wrappanel but width of controls is NaN so i am not able to set location(Y co ordinate) of next checkbox. int lastheight = 10; private void btnadd_Click(object sender, RoutedEventArgs e) { CheckBox chk_add = new CheckBox(); chk_add.MaxWidth = 100; TextBlock tb_add = new TextBlock(); tb_add.MaxWidth = 100; tb_add.TextWrapping = TextWrapping.Wrap; tb_add.Text = "Here is long text so that text block will get split over two lines....... blah blah blah"; chk_add.Content=tb_add;     chk_add.Margin = new Thickness(10, lastheight, 0, 0); wrapPanel1.Children.Add(chk_add); lastheight += (int)chk_add.Width; } Can any any one have idea how can i tackle this issue.

How to customizing TextBlock "line breaking" algorithm in TextWrapping?

Hi all, is it possible to associate a custom line breaking algorithm to a TextBlock in order to choose when breaking line? For example I have a text like the following one "Building 1.Floor 1.Room 4" and I would like auto-breaking only on "dots" character or on long text. For example the following are good breaking for me: Building 1.Floor 1. Room 4 or Building 1. Floor 1...   Is a good idea using a Converter for achieving this? Thanks all, Marzio.

Is there a method that returns the control's type, such as "TextBox", "TextBlock", "Canvas", etc.,

Hello, I have a method that is passed in a FrameworkElement Ctrl.  When I use Ctrl.GetType().ToString() I get "System.Window.Controls.TextBox" or another string if a different type of control is passed in.  All I am interested in is the text after the last dot/period.  In my searching I thought I came across something that just returned the portion I'm looking for, but now can't find it. Is there a method that returns the control's type, such as "TextBox", "TextBlock", "Canvas", etc., without its parents? Regards, Robert

Write to TextBlock



I added a TextBlock to a WPF window and I need to write something in it as I am doing some operations.

Like I would use Console.WriteLine("Something") in a console application.

How can I this this?

I tried to use a TextWriterProxy to write in the TextBlock but no luck:


 public class TextWriterProxy : TextWriter {

  private List<TextWriter> _writers = new List<TextWriter>();

  public override Encoding Encoding { get { return Encoding.Default; } } // Encoding

  public override string NewLine { 
   get { return base.NewLine; }
   set {
    foreach (TextWriter tw in _writers)
     tw.NewLine = value;
    base.NewLine = value;

How does TextBlock.Foreground property setter in the style of a Button get applied


I am new to WPF. Could someone please explain how the TextBlock.Foreground property setter in the following code actually affect the colour of the displayed text in the button? As far as I know, there is no property named TextBlock in the Button class.<Window x:

How can i change TextBlock color at Runtime..??


I'm having a TreeView control like..

<TreeView Name="treeViewInstance" Height="auto" SelectedItemChanged="tv_SelectedItemChanged" 
                 ItemsSource="{Binding Source={StaticResource engInstance}}">
                <HierarchicalDataTemplate DataType

Can we bind a StringBuilder to Textblock Text ?

<TextBlock Text="{Binding Path=Pval, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

public StringBuilder Pval { get; set; }

StringBuilder Pval= new StringBuilder(1000);

Find control TextBlock inside Listbox.ItemTemplate

Hello, I'm a big question, I have a XAML code, where it i
insert a TextBlock to the name "tbNomeHotel" but I can not
call it in C # code, for example: string = xxx tbNomeHotel.Text;

this only happens when the TextBlock is between the tags, and <ListBox.ItemTemplate> <DataTemplate>, which make the data come directly from the database and are displayed in a list.

below is the XAML code, where the bank's value is displayed in a ListBox, if the name of a hotel either!

I like to refer to the TextBlock component in my C # code, so I can use it as a parameter for other queries??

eg>> string xxx = tbNomeHotel.Text;



Name = <StackPanel "stkPanel" Orientation="Horizontal" Width="419">


TextBlock simple databinding



I am attempting to databing a textblock in xaml to a public property within my class. I did first try binding to an object and a string value within it and it didn't work so I thought I would make it even easier by creating in the codebehind a public string as so:

public String TestBind = "Hello";

then in xaml





WPF: what control we should use if we need draw a line between to textBlock?


We need draw a line between two textBlocks.

The two textblocks position will change base on the given space.

So we hope the line width will automatically change base on two textblocks position.

We use Path, however, when the textblock positions change, the path will off (not connect to) two textblocks.

What control we should use in this case? thx!


Image doesn't display in the TextBlock!


This is my code.


   Image imgMessage = new Image();
      BitmapImage bi = new BitmapImage();

      bi.UriSource = new Uri(@"/imgMessage.png", UriKind.RelativeOrAbsolute);

      imgMessage.Source = bi;

      TextBlock tb = new TextBlock();
      InlineUIContainer iuc = new InlineUIContainer(imgMessage);



that code is image shows a TextBlock within the code.

But, isn`t work!

Why isn't my first textblock showing up?


I've got a groupbox with a stackpanel and within that, 2 textblocks. For some reason only the second textblock shows up.  The first one doesn't appear at all.  What's what I've got:

<GroupBox Name="gbScreenersComments" Header="Screener's Comments">
	<ListBox Name="lbScreenersComments" MinWidth="220" ScrollViewer.VerticalScrollBarVisibility=&q

Cannot set Text in a TextBlock?


I am having the most bizarre problem - I cannot change the contents of a TextBlock. This is only 1 place in my program; in other places I have no issue. Just a simple command like

MyTextBlock.Text = "Hello there";

does nothing. I tried first populating its contents (or not), changing alignment, font weight - nothing. Must be something obvious I am missing here - hopefully someone can shed some light. Thanks much.

TextBlock Text not refreshed after raising PropertyChanged - object instance the same, ToString() re



I am working with an object that handles localized strings.  The object type (LocalizedString) provides the correct localized string in its ToString() method.

I have a view model that exposes a property of type LocalizedString.  When my current thread and ui culture is changed, I raise the property changed event for this property, however the strings in the UI do not get updated.

I narrowed it down some to discover that it stops working after the value has been read from the property once.  If instead of just raising property changed when the culture changes I do this:


LocalizedString temp = MyProperty;
MyProperty = null;
MyProperty = temp; // <-- property changed gets raised in the setter 


It seems to work.  The only difference is that the LocalizedString object instance changed.

Basically I believe what happens is this:  The dependency property (TextBlock.Text in this case) gets notified that the bound value has changed.  It goes and retrieves the property value (LocalizedString object), does a comparison and sees that the previous value and the new value are the same object instance, and stops - does not refresh the

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend