textblock

Custom textblock that transforms its content to different color

China☆狼群 提交于 2019-12-02 11:27:12
I will write a custom textblock that splits its text content. It will make texts diffent colors depending on conditions and the texts will be separated with commas. Commas will remain black. I don't know how to start. Could you please provide help to start? Thanks in advance Below user control uses an items control to show each token with some random color. Usage: <local:ColorTextBlock Text="abcd,abcde, abc, abcdef, abc, abcde, "/> XAML: <UserControl x:Class="WpfApplication1.ColorTextBlock" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com

Reusing Text views and Grid

社会主义新天地 提交于 2019-12-02 08:59:44
I am working on windows phone 8 app. I am dynamically creating multiple Textview and Grid inside For loop. for (int j = 0; j < 300; j++) { Image image = new Image(); image.Source = new BitmapImage(new Uri("/Images/sample256.png", UriKind.RelativeOrAbsolute)); image.Tag = i.ToString(); Grid questionGrid = new Grid(); questionGrid.HorizontalAlignment = HorizontalAlignment.Center; questionGrid.VerticalAlignment = VerticalAlignment.Center; TextBlock question = new TextBlock(); question.TextWrapping = TextWrapping.Wrap; question.TextAlignment = TextAlignment.Center; question.Text = " this is the

WPF textblock binding in XAML

痞子三分冷 提交于 2019-12-02 08:38:12
问题 I'm updating some existing WPF code and my application has a number of textblocks defined like this: <TextBlock x:Name="textBlockPropertyA"><Run Text="{Binding PropertyA}"/></TextBlock> In this case, "PropertyA" is a property of my business class object defined like this: public class MyBusinessObject : INotifyPropertyChanged { private void OnPropertyChanged(PropertyChangedEventArgs e) { if (PropertyChanged != null) { PropertyChanged(this, e); } } private string _propertyA; public string

Bind WPF TextBlock to text file

隐身守侯 提交于 2019-12-02 06:34:01
How can I bind a WPF TextBlock to a text file? I want for the TextBlock to display the content of the file. You need to read the file into a string in memory and bind to that string instead. View model: class ViewModel { public string FileText { get; set; } public void ReadFile(string path) { FileText = File.ReadAllText(path); } } XAML: <TextBlock Text="{Binding FileText}"/> Jodrell If you want the text to be formatted my inline markup you could look at the sub-class of TextBlock I made here . There is a convertor between a String of xaml markup and an InlineCollection(actually a generic list

WPF's TextBlock differences between Windows 7 and Windows 8

强颜欢笑 提交于 2019-12-02 05:51:05
问题 While investigating some unit tests which fail only on my machine, I noticed that TextBlock presents text differently on Windows 7 and Windows 8 machines. To inspect the issue, I created sample application containing just one TextBlock: <Window x:Class="WpfApplication1.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 Text="yo" FontSize="100"

Changing the colors of substrings within the bound Text of a TextBlock

荒凉一梦 提交于 2019-12-02 03:33:25
问题 I am binding some property into my TextBlock : <TextBlock Text="{Binding Status}" Foreground="{Binding RealTimeStatus,Converter={my:RealTimeStatusToColorConverter}}" /> Status is simple text and RealTimeStatus is enum . For each enum value I am changing my TextBlock Foreground color. Sometimes my Status message contains numbers. That message gets the appropriate color according to the enum value, but I wonder if I can change the colors of the numbers inside this message, so the numbers will

Changing the colors of substrings within the bound Text of a TextBlock

删除回忆录丶 提交于 2019-12-02 01:23:27
I am binding some property into my TextBlock : <TextBlock Text="{Binding Status}" Foreground="{Binding RealTimeStatus,Converter={my:RealTimeStatusToColorConverter}}" /> Status is simple text and RealTimeStatus is enum . For each enum value I am changing my TextBlock Foreground color. Sometimes my Status message contains numbers. That message gets the appropriate color according to the enum value, but I wonder if I can change the colors of the numbers inside this message, so the numbers will get different color from the rest of the text. Edit. XAML <TextBlock my:TextBlockExt.XAMLText="{Binding

How to display simple HTML in a Silverlight textblock?

五迷三道 提交于 2019-12-01 17:31:08
I've got a source of data that has HTML tags in it (B, I, A) and need to display this in a Silverlight ListBox. Searching around it seems to be an issue but most of the posts are old and have to do with Silverlight 1 it seems. What is currently the best way to display simple HTML with Silverlight, if nothing else, just the B, I and A tags for bold, italic and hyperlinks? Noldorin There's no native support in Silverlight 2.0. However, someone has gone and created a HtmlTextBlock control which should be suitable for your purposes. Check out the author's block post on the subject. There's also a

How to display simple HTML in a Silverlight textblock?

回眸只為那壹抹淺笑 提交于 2019-12-01 15:53:09
问题 I've got a source of data that has HTML tags in it (B, I, A) and need to display this in a Silverlight ListBox. Searching around it seems to be an issue but most of the posts are old and have to do with Silverlight 1 it seems. What is currently the best way to display simple HTML with Silverlight, if nothing else, just the B, I and A tags for bold, italic and hyperlinks? 回答1: There's no native support in Silverlight 2.0. However, someone has gone and created a HtmlTextBlock control which

How to data bind multiple values to a single TextBlock.Text in WP7?

倾然丶 夕夏残阳落幕 提交于 2019-12-01 15:52:29
How can I bind 2 properties to a single TextBlock.Text (eg. first name and last name or current value and max value)? something like: // IValueConverter public object Convert( .... ) { return string.Format("{0} (max: {1})", currentValue, maxValue); } The problem is I want TextBlock.Text to be updated when currentValue or maxValue has changed. So how can I listen to changes from 2 or more properties using data binding? Is there another way than usering IValueConverter ? Silverlight 3 (on which the Windows Phone 7 framework is built) doesn't support MultiBinding, which is what you would use to