textblock

WP7 TextBlock inside a ListBox not wrapping text

泪湿孤枕 提交于 2019-12-21 16:56:14
问题 I have a ListBox which has StackPanel s holding a TextBlock and an Image horizontally, followed by a ContentPresenter . This is what the XAML looks like: <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <ListBox x:Name="MainListBox" Margin="12,0,12,0" SelectionChanged="MainListBox_SelectionChanged"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <toolkit:ContextMenuService.ContextMenu> <toolkit:ContextMenu x:Name="ContextMenu" Opened="ContextMenu_Opened"> <toolkit:MenuItem

WPF — it's gotta be easier than I'm making it

只谈情不闲聊 提交于 2019-12-21 12:27:29
问题 I'm having the darndest time figuring this out: say I've got two Button and three TextBlocks. I want either button to trigger a simple Storyboard on ALL TextBlocks. Currently I'm trying to define a generic Textblock style that contains the Storyboard, and then the trigger comes from any Button click. This is the closest I've come but the app crashes on startup...what am I don't wrong here: <Window.Resources> <Style TargetType="TextBlock" > <Setter Property="Foreground" Value="Blue" /> <Style

WPF: How to make empty TextBlock not to occupy space?

泪湿孤枕 提交于 2019-12-21 08:49:30
问题 Let's say that I have a simple layout such as this: <StackPanel> <TextBlock Text="{Binding Path=Title}" /> <TextBlock Text="{Binding Path=ShortDescription}" /> <TextBlock Text="{Binding Path=LongDescription}" /> </StackPanel> Now when I have ShortDescription set to null or empty string there's still a gap in place of second TextBlock. Is there some property to prevent an empty textblock from occupying space? Or should I use some other control? Thanks. 回答1: You want to set the visibility of

Auto detect URL, phone number, email in TextBlock

回眸只為那壹抹淺笑 提交于 2019-12-21 06:28:12
问题 I would like to automatically highlight URL, Email and phone number in UWP. It is possible in Android but it seems this features has been forgotten by Microsoft. In my use case, I get the text from a web service, so I don't know the text format which is a user text input on the web platform. 回答1: The platform is not supporting this feature (yet). When I've to do the same thing, I've ended with my own solution which is to: create an attached property receiving the text to format use some regex

Custom textblock that transforms its content to different color

拈花ヽ惹草 提交于 2019-12-20 06:47:57
问题 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 回答1: 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

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

杀马特。学长 韩版系。学妹 提交于 2019-12-19 15:40:30
问题 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 ? 回答1: Silverlight 3 (on

How is it possible to stuff a Grid inside a TextBlock?

本小妞迷上赌 提交于 2019-12-19 10:23:30
问题 The other day I ran into the following xaml and I freaked out: <Grid x:Name="LayoutRoot"> <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center"> <Grid> <Rectangle Fill="AliceBlue" Width="25" Height="25"/> </Grid> </TextBlock> </Grid> In other words ... how is it possible to put a Grid inside a TextBlock? 回答1: The simple answer is that you can drive TextBlock in two ways ... through the Text property and through the Inlines collection. In this case, you are using the Inlines

WPF TextBlock: How to evenly space displayed characters?

左心房为你撑大大i 提交于 2019-12-19 08:39:44
问题 I need to display a string with each character displayed every x pixels. (x is accross the whole string). e.g.: "Hello" -> H at position (pixel) 0, e at position 50, l at 100, l at 150, o at 200. Of course I could use a TextBlock for each character but it seems overkill. TranslateTransform doesn't seem to do the trick: It offsets my characters relatively to the END of the previous character, which is not what I want. TIA for your help. 回答1: I don't believe there's an in-built abilty to do

C# WPF - ScrollViewer + TextBlock troubles

江枫思渺然 提交于 2019-12-18 12:50:34
问题 I have a TextBlock within a ScrollViewer that aligns with stretch to its window. I need the TextBlock to behave as the following: Resizes with window, no scrollbars When resized below a certain width the TextBlock needs to keep a MinWidth and scrollbars should appear TextWrapping or TextTrimming should work appropriately How can I get this functionality? I have tried several ways, involving bindings to ActualWidth & ActualHeight , but can't get it to work. This can't be that difficult, what

How to a add a command to a WPF TextBlock?

ぃ、小莉子 提交于 2019-12-18 10:37:17
问题 I'd like to be able to click a textblock and have it run a Command. Is this possible? (if not do I just somehow make a tranparent button over it or something?) 回答1: You can use a InputBinding. <TextBlock Text="Hello"> <TextBlock.InputBindings> <MouseBinding Command="" MouseAction="LeftClick" /> </TextBlock.InputBindings> </TextBlock> Edit: Hyperlink is probably worth a mention too. <TextBlock><Hyperlink Command="" TextDecorations="None" Foreground="Black">Hello</Hyperlink></TextBlock> 回答2: