textblock

Detect is a website address or email address on textblock

血红的双手。 提交于 2019-12-08 12:50:11
问题 I have a TextBlock whose data comes from JSON. I would like if the textblock the website address or email, the text color becomes blue and the user can click (if the email address it will go to the email application and the user can write an email directly to this address. Meanwhile, if the website address, it will immediately open the web browser). XAML: <TextBlock x:Name="DetailDeskripsi" Width="290" Text="{Binding Deskripsi}" VerticalAlignment="Top" HorizontalAlignment="Left" Height="auto"

How do I display changing time within a TextBlock?

血红的双手。 提交于 2019-12-08 03:45:07
问题 So I have a stopwatch and all I want is for it to be display on a textblock. How can I do that? 回答1: Create a TimerViewModel, that looks something like this: public class TimerViewModel : INotifyPropertyChanged { public TimerViewModel() { timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(1); timer.Tick += new EventHandler(timer_Tick); timer.Start(); startTime = DateTime.Now; } private DispatcherTimer timer; private DateTime startTime; public event

TextBlock Text property can't be set via style trigger if non-empty - why?

你说的曾经没有我的故事 提交于 2019-12-07 06:02:44
问题 The XAML below does not work (the text does not change when mousing over): <Window.Resources> <Style TargetType="TextBlock"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="Text" Value="hover"/> </Trigger> </Style.Triggers> </Style> </Window.Resources> <Grid> <TextBlock Text="original"/> </Grid> But, if the Text attribute is missing: <Grid> <TextBlock/> </Grid> The text does change on mouse over. Anybody knows the theory behind this? 回答1: It's a

WPF Textblock TargetNullValue not working?

大憨熊 提交于 2019-12-07 03:09:44
问题 I have a wpf textblock as below: <TextBlock Text="{Binding [someViewModel].SomeVar.SomeSubVar.Name, TargetNullValue='-'}"/> At my viewmodel side, I'll have my own logic that in the end, SomeVar.SomeSubVar will be null. If I want to show a default value for this TextBlock I know I can declare and initiate SomeVar.SomeSubVar and assign default value into SomeVar.SomeSubVar.Name but I would like to use TargetNullValue instead. May I know which part is wrong? 回答1: You might look at using

TextBlock to Display HTML in WPF

佐手、 提交于 2019-12-06 18:06:36
问题 Is there anyway to display HTML from a string variable to the TextBlock in WPF? 回答1: Can't do it in TextBlock, you need a WebBrowser control (or Frame, but it is obsolete). Feed descriptions, btw, can contain JavaScript - would be pretty hard for TextBlock to handle ;) 回答2: Maybe you can use this WPF Html supported TextBlock 回答3: string html = " <div>hi</div> <div> </div> <p>this is the new line <br /><br />second line</p> <p>third line</p> "; TextBlock.Text = Windows.Data.Html.HtmlUtilities

How to refer MaxWidth=“??” of TextBlock to Owner ActualWidth?

那年仲夏 提交于 2019-12-06 16:54:07
问题 How to refer MaxWidth="??" of TextBlock to stpMessage ActualWidth ? <StackPanel Name="stpMessage" Orientation="Horizontal" Margin="0,5,0,0"> <Grid > <Grid.ColumnDefinitions> <ColumnDefinition Width="2*" /> <ColumnDefinition Width="2*" /> </Grid.ColumnDefinitions> <TextBlock Margin="0,0,0,0" Foreground="Blue" TextWrapping="Wrap">@ToUserName</TextBlock> <StackPanel Grid.Column="1"> <TextBlock Margin="5,0,0,0" Text="{Binding Path=Text}" MinHeight="20" MinWidth="200" HorizontalAlignment="Stretch"

How do I display changing time within a TextBlock?

[亡魂溺海] 提交于 2019-12-06 15:50:40
So I have a stopwatch and all I want is for it to be display on a textblock. How can I do that? Create a TimerViewModel, that looks something like this: public class TimerViewModel : INotifyPropertyChanged { public TimerViewModel() { timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(1); timer.Tick += new EventHandler(timer_Tick); timer.Start(); startTime = DateTime.Now; } private DispatcherTimer timer; private DateTime startTime; public event PropertyChangedEventHandler PropertyChanged; public TimeSpan TimeFromStart { get { return DateTime.Now - startTime; } } private void

How to Change the SelectedItem Foreground Text of ListBox Item

别说谁变了你拦得住时间么 提交于 2019-12-06 09:56:46
问题 I have the following ListBox below. I am not sure how to change the Foreground of a selected item's textblock text when an item is selected, and then back to the original foreground color when an item is unselected (most likely occurring when another item in the ListBox is selected afterwards)? <ListBox Name="ListBox" SelectionMode="Single" ItemsSource="{Binding}" Margin="{Binding}" toolkit:TiltEffect.IsTiltEnabled="True" SelectionChanged="ListBox_SelectionChanged" > <ListBox.ItemsPanel>

Default TextBlock style overriding button text color

孤街醉人 提交于 2019-12-06 04:04:46
问题 My problem occurs with WPF in .NET 3.5 SP1 and can be described as follows: I have a default Style hitting all TextBlock elements in my UI. That is how it looks: <Style TargetType="{x:Type TextBlock}"> <Setter Property="TextTrimming" Value="CharacterEllipsis"/> <Setter Property="Foreground" Value="Red"/> </Style> That works fine for all TextBlock s. In addition to that I have a Button style including a ControlTemplate that looks like this (shortened): <Style x:Key="MyButtonStyle" TargetType="

Binding text to attached property

风格不统一 提交于 2019-12-05 23:57:41
My question is similar to this: WPF Generate TextBlock Inlines but I don't have enough reputation to comment. Here is the attached property class: public class Attached { public static readonly DependencyProperty FormattedTextProperty = DependencyProperty.RegisterAttached( "FormattedText", typeof(string), typeof(TextBlock), new FrameworkPropertyMetadata(string.Empty, FrameworkPropertyMetadataOptions.AffectsMeasure)); public static void SetFormattedText(DependencyObject textBlock, string value) { textBlock.SetValue(FormattedTextProperty, value); } public static string GetFormattedText