textblock

Wpf Binding Stringformat to show only first character

拈花ヽ惹草 提交于 2019-11-29 12:02:27
Is there any way so that i can show only first character of a Bound string on a textblock..? For eg;If i Bind 'Male', my textblock should only show 'M'..... You might use a value converter to return a string prefix: class PrefixValueConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string s = value.ToString(); int prefixLength; if (!int.TryParse(parameter.ToString(), out prefixLength) || s.Length <= prefixLength) { return s; } return s.Substring(0, prefixLength); } public object ConvertBack(object

Programmatically determining max fit in textbox (WP7)

帅比萌擦擦* 提交于 2019-11-29 04:48:12
I'm currently writing an eBook reader for Windows Phone Seven, and I'm trying to style it like the Kindle reader. In order to do so, I need to split my books up into pages, and this is going to get a lot more complex when variable font sizes are added. To do this at the moment, I just add a word at a time into the textblock until it becomes higher than its container. As you can imagine though, with a document of over 120,000 words, this takes an unacceptable period of time. Is there a way I can find out when the text would exceed the bounds (logically dividing it into pages), without having to

Multiple Colors In TextBlock

无人久伴 提交于 2019-11-29 04:28:41
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 characters in different colors. If so is it possible to add these colors dynamically for eg. If I click a

Is this slow WPF TextBlock performance expected?

时间秒杀一切 提交于 2019-11-29 01:22:13
I am doing some benchmarking to determine if I can use WPF for a new product. However, early performance results are disappointing. I made a quick app that uses data binding to display a bunch of random text inside of a list box every 100 ms and it was eating up ~15% CPU. So I made another quick app that skipped the data binding/data template scheme and does nothing but update 10 TextBlocks that are inside of a ListBox every 100 ms (the actual product wouldn't require 100 ms updates, more like 500 ms max, but this is a stress test). I'm still seeing ~5-10% CPU usage. Why is this so high? Is it

Automatic vertical scroll bar in WPF TextBlock?

喜夏-厌秋 提交于 2019-11-28 15:10:12
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. Wrap it in a scroll viewer: <ScrollViewer> <TextBlock /> </ScrollViewer> NOTE this answer applies to a TextBlock (a read-only

programmatically make textblock with hyperlink in between text

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 13:26:49
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 Text property to 'click please' and adding a Hyperlink to TextBlock.Content . But how do I position the

How to grow/shrink a TextBlock (Font Size) to the available space in WPF?

烂漫一生 提交于 2019-11-28 09:37:06
I've seen this question asked a lot, however, to the opposite of what I'm looking for. While other people want a control to size itself based on the size of text, I'm trying to figure out is if there is a way to grow the size of text to the amount of space available. Take the idea of a digital clock window and you want the numbers stating the time to grow (or shrink) based on the size of the window the clock is in. If there isn't a way to automatically do this any pointers to a programmatic way I can get this accomplished? The WPF Viewbox control will grow / shrink its contents to the

Align bottoms of text in controls

拈花ヽ惹草 提交于 2019-11-28 09:06:53
The following snippet: <Window x:Class="Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Grid> <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center"> <Label Content="Name:"/> <Label Content="Itzhak Perlman" FontSize="44"/> </StackPanel> </Grid> </Window> Renders the following: Is there any way I can set in the Labels' styles so that their text bottoms should be aligned? I have the same question with TextBlocks as well. NOTE: since I've been struggling with this issue for a

How to detect a change in the Text property of a TextBlock?

房东的猫 提交于 2019-11-28 09:03:33
Is there any way to detect a change in the Text property of a TextBlock element using events? (I'm trying to provide an animation for highlighting the TextBlocks whose Text property change within a DataGrid) As far as I can understand there isn't any textchanged event in TextBlock. Looking at your requirement, I feel that re-templating a textbox will also not be a viable solution. From my preliminary searching around, this seems to be a possible solution. Tono Nam It's easier than that! Late answer, but much simpler. // assume textBlock is your TextBlock var dp = DependencyPropertyDescriptor

WPF TextBlock font resize to fill available space in a Grid

限于喜欢 提交于 2019-11-28 05:13:22
I have some text that is displayed at run time in a textblock. I want the font size to be the biggest it can be to fill the area that is given. I think I have the textblock setup correctly to "autosize" and I try to increase the font size till the textblock is bigger than than its parent then decrease the font size by 1. The problem is I can't get the control to redraw/recompute its size. Is the a better way to do that? Or is there a way I can make my method work? Jobi Joy Wrap the TextBlock inside a ViewBox : <Grid> <Viewbox> <TextBlock TextWrapping="Wrap" Text="Some Text" /> </Viewbox> <