textblock

Force TextBlock to wrap in WPF ListBox

笑着哭i 提交于 2019-11-26 18:06:10
问题 I have a WPF listbox which displays messages. It contains an avatar on the left side and the username and message stacked vertically to the right of the avatar. The layout is fine until the message text should word wrap, but instead I get a horizontal scroll bar on the listbox. I've Googled and found solutions to similar issues, but none of them worked. <ListBox HorizontalContentAlignment="Stretch" ItemsSource="{Binding Path=FriendsTimeline}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel

Data binding the TextBlock.Inlines

拈花ヽ惹草 提交于 2019-11-26 17:53:59
My WPF App receives a stream of messages from a backend service that I need to display in the UI. These messages vary widely and I want to have different visual layout (string formats, colors, Fonts, icons, whatever etc.) for each message. I was hoping to just be able to create an inline (Run, TextBlock, Italic etc) for each message then somehow put them all in a ObservableCollection<> and using he magic of WPF Data Binding on my TextBlock.Inlines in the UI. I couldn't find how to do this, is this possible? itowlson This is not possible because the TextBlock.Inlines property is not a

Why isn't TextBox.Text in WPF animatable?

ⅰ亾dé卋堺 提交于 2019-11-26 17:01:31
问题 Ok, I have just run into something that is really catching me off-guard. I was helping a fellow developer with a couple of unrelated questions and in his project he was animating text into some TextBlock(s). So, I went back to my desk and recreated the project (in order to answer his questions), but I accidentally used TextBox instead of TextBlock . My text wasn't animating at all! (A lot of help, I was!) Eventually, I figured out that his xaml was using TextBlock and mine was using TextBox.

How to make all text upper case / capital?

南笙酒味 提交于 2019-11-26 16:39:13
问题 I want all texts in TextBlock , Label , MenuItem.Header to be displayed in upper case. The strings are taken from a ResourceDictionary e.g.: <TextBlock Text="{StaticResource String1}"/> <MenuItem Header="{StaticResource MenuItemDoThisAndThat}"/> etc. (also for Label and other controls) I cannot use a value converter because there is no binding. I don't want to make the strings upper case in the dictionary itself. 回答1: You still can use a converter, just set the textvalue in the source of the

How to bind a TextBlock to a resource containing formatted text?

可紊 提交于 2019-11-26 13:10:36
问题 I have a TextBlock in my WPF window. <TextBlock> Some <Bold>formatted</Bold> text. </TextBlock> When it is rendered it looks like this, Some formatted text. My question is, can I bind this inline "content" to a resource in my application? I got as far as: Making an application resource string, myText="Some <Bold>formatted</Bold> text." and the following xaml (Some code omitted for brevity) <Window xmlns:props="clr-namespace:MyApp.Properties"> <Window.Resources> <props:Resources x:Key=

Any way to make a WPF textblock selectable?

☆樱花仙子☆ 提交于 2019-11-26 12:03:49
I want to make the text displayed in the Witty , an open source Twitter client, selectable. It is currently displayed using a custom textblock. I need to use a TextBlock because I'm working with the textblock's inlines to display and format the @username and links as hyperlinks. A frequent request is to be able to copy-paste the text. In order to do that I need to make the TextBlock selectable. I tried to get it to work by displaying the text using a read-only TextBox styled to look like a textblock but this will not work in my case because a TextBox does not have inlines. In other words, I

Difference between Label and TextBlock

走远了吗. 提交于 2019-11-26 11:56:20
问题 According to the Windows Applications Development with Microsoft .NET 4 70-511 Training Kit What is the difference between the Label control and TextBlock control since both are content controls and just displaying text? 回答1: TextBlock is not a control Even though TextBlock lives in the System.Windows.Controls namespace, it is not a control. It derives directly from FrameworkElement . Label, on the other hand, derives from ContentControl . This means that Label can: Be given a custom control

How to bind multiple values to a single WPF TextBlock?

☆樱花仙子☆ 提交于 2019-11-26 11:05:34
I'm currently using the TextBlock below to bind the value of a property named Name : <TextBlock Text="{Binding Name}" /> Now, I want to bind another property named ID to the same TextBlock . Is it possible to bind two or more values to the same TextBlock ? Can it be done with simple concatenation, like Name + ID and, if not, how else could this be approached? Richard McGuire You can use a MultiBinding combined with the StringFormat property. Usage would resemble the following: <TextBlock> <TextBlock.Text> <MultiBinding StringFormat="{}{0} + {1}"> <Binding Path="Name" /> <Binding Path="ID" /> <

How can I determine if my TextBlock text is being trimmed?

六月ゝ 毕业季﹏ 提交于 2019-11-26 10:44:10
问题 The following textblock wraps and trims as expected. The elipsis \"...\" is displayed when the text is trimmed. <TextBlock MaxWidth=\"60\" MaxHeight=\"60\" Text=\"This is some long text which I would like to wrap.\" TextWrapping=\"Wrap\" TextTrimming=\"CharacterEllipsis\" /> I would like to display a tooltip over the text with the full text, but only if the text is trimmed. I\'m not sure how to reliably determine if the \"...\" is being shown or not. How do I determine if the text is being

Add hyperlink to textblock wpf

不问归期 提交于 2019-11-26 09:34:49
问题 Greetings, I have some text in a db and it is as follows: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis tellus nisl, venenatis et pharetra ac, tempor sed sapien. Integer pellentesque blandit velit, in tempus urna semper sit amet. Duis mollis, libero ut consectetur interdum, massa tellus posuere nisi, eu aliquet elit lacus nec erat. Praesent a commodo quam. **[a href=\'http://somesite.com\']some site[/a]**Suspendisse at nisi sit amet massa molestie gravida feugiat ac sem.