textblock

WPF: How to make textblock fire key event?

随声附和 提交于 2019-12-10 15:28:57
问题 TextBlock has KeyDown and KeyUp event, but it's never fired. Is there a way to make it happen? I just need to detect if any key is pressed. 回答1: First of all you will need to set the Focusable Property of your TextBlock to True, This will allow you to Tab to the Item but not Click to select it, but if you handle the MouseDown Event you can manualy set Focus to your TextBlock. MainWindow.xaml <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml

TextBlock brush giving incorrect color

北城余情 提交于 2019-12-10 13:39:33
问题 I have a TextBlock and a Rectangle, both sitting in an empty WPF4 window. The TextBlock's Foreground and the Rectangle's Fill are both set to a SolidColorBrush with value #80800000. This is what it looks like: The Rectangle's color is correct (a 50% transparent maroon) but the TextBlock gives a flat grey. What's going on? EDIT: Here's the XAML: <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com

making textblock readonly

白昼怎懂夜的黑 提交于 2019-12-10 12:29:17
问题 currently i have a textblock placed in a scroll viewer control. How do i make the textblock read only? 回答1: Textblocks are already readonly. They are intended to display a small amount of flow text. Perhaps you thought you were dealing with a TextBox instead? 回答2: BinaryTox1n answered your question, but if you need the text to be selectable see the previous StackOverflow question. 回答3: Bind the Textblock to a property with only a getter and it will be a readonly textblock. 来源: https:/

Updating value of TextBlock in wpf dynamically [Sovled]

坚强是说给别人听的谎言 提交于 2019-12-10 12:25:01
问题 I have text block on my UI. I would like to display some text on the text block dynamically. I have implemented it as given in the below code. however i do not see the values updating dynamically. I do see only the last updated value on UI text block. I have included a delay to notice the change. Please provide any solution or comment for more info.Thank you in advance. Code: namespace TxtBlock { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class

How to TextWrap a TextBlock within a width Auto Column?

扶醉桌前 提交于 2019-12-10 01:14:23
问题 Consider something as follows: <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <TextBlock x:Name="WrapTextBlock" Grid.Column="0" Text="123 456 789 0123 4456 123 123 123 123 1 23 123 " TextWrapping="Wrap" /> <TextBlock x:Name="NotWrapTextBlock" Grid.Column="1" Text="GGG" /> </Grid> This XAML will allow WrapTextBlock text to be wrap, doing this, WrapTextBlock will take all the space and push NotWrapTextBlock to the right.

How do the default color, font family and font size for a TextBlock and Label get set in an WPF app?

帅比萌擦擦* 提交于 2019-12-09 13:30:21
问题 Edit: I guess the question wasn't stated very clearly. It actually composes of 4 separate ones: How does a TextBlock get its default color, if the client app doesn't provide any style, either programmatically or through xaml? How does a Label get its default color? How does a TextBlock get its default font size and font family, if the client app doesn't provide any style, either programmatically or through xaml? How does a Label get its default font size and font family? BTW, the questions

Get the lines of the TextBlock according to the TextWrapping property?

可紊 提交于 2019-12-09 12:41:43
问题 I have a TextBlock in WPF application. The ( Text , Width , Height , TextWrapping , FontSize , FontWeight , FontFamily ) properties of this TextBlock is dynamic (entered by the user at the runtime). Every time the user changes one of the previous properties, the Content property of the TextBlock is changed at the runtime. (everything is ok until here) Now, I need to get the lines of that TextBlock according to the previously specified properties. That means I need the lines that TextWrapping

TextBlock text doesn't wrap when placed inside a ViewBox

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 02:56:35
问题 I have a TextBlock with a long line of text which I want to wrap. I've placed the TextBlock within a ViewBox expecting the text size to change while still wrapping, however this doesn't seem to happen. The ViewBox just resizes the TextBox so that all the text fits on one line making the text really small. How can I use the ViewBox to resize the text while still using TextWrapping. Here is my code: <Viewbox> <TextBlock Text="The Option text can also dynamically grow/shrink to fit more content.

How do I measure the size of a TextBlock in WPF before it is rendered?

不打扰是莪最后的温柔 提交于 2019-12-09 02:29:39
问题 I have a WPF DataTemplate with two TextBlock controls (stacked) and then some other elements underneath. Due to some complicated layout code, I need to know the height of the two TextBlock elements so that I can draw some fancy connector lines, and line up other controls, etc. If I know the text that's going into the TextBlocks, and I know the font, etc., is there some way I can compute or measure the height of these TextBlocks without actually rendering them? 回答1: I think it should be

Give TextBlock Default Value if result returns null

末鹿安然 提交于 2019-12-08 19:18:19
问题 Hello I am trying to give a default value to a textblock if the results returned are null Here is what I am trying! All that returns is the String Format I set! <TextBlock x:Name="NameTxtBlock" Grid.Column="0" Margin="0,0,40,0" FontFamily="Segoe UI" FontSize="14" Text="{Binding Name, StringFormat='Item Name: {0}'}" Padding="2"> <TextBlock.Style> <Style TargetType="TextBlock" > <Style.Triggers> <DataTrigger Binding="{Binding ElementName=NameTxtBlock, Path=Text}" Value="{x:Null}"> <Setter