textblock

WPF format DateTime in TextBlock?

好久不见. 提交于 2019-11-28 04:49:21
I have a TextBlock that is bound to a DateTime property. How do I configure the format of the date? Martin Harris There is a string format property available when you are declaring the binding: <TextBox Text="{Binding Path=DateTimeValue, StringFormat=dd-MM-yyyy}" /> (You need to be on .NET 3.5 SP1 for this property to exist) Brian Hinchey If you want to use a common format string between bindings, you could declare the binding like this: <Textbox Text={Binding Path=DateTimeValue, StringFormat={x:Static local:Constants.DateTimeUiFormat}} /> With your constants class like this: public static

Can I have multiple colors in a single TextBlock in WPF?

杀马特。学长 韩版系。学妹 提交于 2019-11-28 03:17:55
问题 I have a line of text in a textblock that reads: "Detected [gesture] with an accuracy of [accuracy]" In WPF, is it possible for me to be able to change the color of the elements within a textblock? Can I have a textblock be multiple colors? For example, I would like the whole TextBlock to be black except the gesture name, which I would like to be red. Is this possible in WPF? 回答1: See if this helps: <TextBlock> Detected <TextBlock Text="{Binding Gesture}" Foreground="Red" /> with an accuracy

Text vertical alignment in WPF TextBlock

天大地大妈咪最大 提交于 2019-11-28 03:04:54
How do I assign vertical center alignment to the text inside a TextBlock? I found TextAlignment property but it is for horizontal text alignment. How do I do it for vertical text alignment? A Textblock itself can't do vertical alignment The best way to do this that I've found is to put the textblock inside a border, so the border does the alignment for you. <Border BorderBrush="{x:Null}" Height="50"> <TextBlock TextWrapping="Wrap" Text="Some Text" VerticalAlignment="Center"/> </Border> Note: This is functionally equivalent to using a grid, it just depends how you want the controls to fit in

Get Displayed Text from TextBlock

偶尔善良 提交于 2019-11-27 20:06:34
I have a simple TextBlock defined like this <StackPanel> <Border Width="106" Height="25" Margin="6" BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left"> <TextBlock Name="myTextBlock" TextTrimming="CharacterEllipsis" Text="TextBlock: Displayed text"/> </Border> </StackPanel> Which outputs like this This will get me "TextBlock: Displayed text" string text = myTextBlock.Text; But is there a way to get the text that's actually displayed on the screen? Meaning "TextBlock: Display..." Thanks You can do this by first retrieving the Drawing object that represents the appearance of the

Multiple Colors In TextBlock

老子叫甜甜 提交于 2019-11-27 18:22:06
问题 Is it possible to add dynamic colors to a TextBlock ..i.e. have one character in one color and the next in another color. <TextBlock Text="{Binding no}" TextWrapping="Wrap" Margin="10,0,0,0" Style="{StaticResource PhoneTextSubtleStyle}" FontSize="40" Foreground="#A400C4FF" > // Can we add something here to specify what colours for what chars </TextBlock> Basically I input a dynamic 4 character sequence from no. I've bound it to this TextBlock inside a ListBox. Is it possible to have the

Text blocks positions and sizes detection in command line mode in tesseract

旧巷老猫 提交于 2019-11-27 16:57:02
问题 tesseract OCR have a command line interface, which allow us to recognize text from images with some parameters. Input argumetns are imagename (path to image) outputbase (name of recognized text) and -psm pagesegmode parameters. pagesegmode values are: 0 = Orientation and script detection (OSD) only. 1 = Automatic page segmentation with OSD. 2 = Automatic page segmentation, but no OSD, or OCR 3 = Fully automatic page segmentation, but no OSD. (Default) 4 = Assume a single column of text of

How to make all text upper case / capital?

痞子三分冷 提交于 2019-11-27 14:17:10
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. You still can use a converter, just set the textvalue in the source of the binding : <TextBlock Text="{Binding Source={StaticResource String1}, Converter ={StaticResource myConverter}

Force TextBlock to wrap in WPF ListBox

回眸只為那壹抹淺笑 提交于 2019-11-27 11:51:49
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 Orientation="Horizontal"> <Border BorderBrush="DarkBlue" BorderThickness="3" CornerRadius="2" Margin=

Automatic vertical scroll bar in WPF TextBlock?

送分小仙女□ 提交于 2019-11-27 09:01:01
问题 I have a TextBlock in WPF. I write many lines to it, far exceeding its vertical height. I expected a vertical scroll bar to appear automatically when that happens, but it didn't. I tried to look for a scroll bar property in the Properties pane, but could not find one. How can I make vertical scroll bar created automatically for my TextBlock once its contents exceed its height? Clarification: I would rather do it from the designer and not by directly writing to the XAML. 回答1: Wrap it in a

programmatically make textblock with hyperlink in between text

蓝咒 提交于 2019-11-27 07:39:02
问题 In XAML I have the following code: <Label Width="120" Height="20" Name="label1" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Bottom"> <TextBlock VerticalAlignment="Center" HorizontalAlignment="Left"> click <Hyperlink RequestNavigate="Hyperlink_RequestNavigate" NavigateUri="foo">here</Hyperlink> please </TextBlock> </Label> Now I'd like to get rid of the whole TextBlock XAML and add that bit programmatically. I have no trouble creating the TextBlock, setting the