I am having hard time to match Special characters set in XAML. I only on the following:
To represent a LineBreak in XAML hyperlink button:
use : > lineBreak <
But What do I use to represent a New Line or LineBreak In XAML hyperlink button??
Example : I want this one line mag : This is line one. This is line two
into this :
This is line one. This is line two.
it seems this \r\n is not working. This is line one \r\n
You've got options. For example;
<HyperlinkButton Content="Line One
Line Two"/>
or
<HyperlinkButton>
<HyperlinkButton.Content>
<TextBlock>
<Run Text="Line 1"/><LineBreak/><Run Text="Line 2"/>
</TextBlock>
</HyperlinkButton.Content>
</HyperlinkButton>
Hope this helps.
Addendum: You can do this stuff in basically anything. WPF, Silverlight, UWP, whatever. It's not WP specific.
You can use preserve. It includes all whitespace, so inputting the exact string you want would involve messing up your indentation, but this will work:
<HyperlinkButton xml:space="preserve">This is line one.
This is line two.</HyperlinkButton>
Related
I'm a little surprised to see that this isn't a feature of the AutoSuggestBox but, I'm trying to configure an AutoSuggestBox to bold any matched text from what gets pulled up.
So it would look like:
[ jay ]
jaydeflix
jaydeflixutil
tommyjay
If anyone has sample code, I'll gladly look at it, but I'll even gladly take a pointer at what to dig into (I'm self-taught, so I'm used to digging, just my binggle-fu is coming up short on this one).
The suggestion list is actually a ListView of AutoSuggestBox. More details please see AutoSuggestBox styles and templates. To define a custom look for each item in the list, use the ItemTemplate property of AutoSuggestBox, for more details about this please check the Text changed section.
The TextBlock can be set with paticial bold text with <Run> tag that you can try to use inside the template. For example:
<AutoSuggestBox
x:Name="asb"
... >
<AutoSuggestBox.ItemTemplate>
<DataTemplate>
<TextBlock>
<Run FontWeight="Bold" Text="{Binding QueryString}"></Run>
<Run Text="{Binding DisplaySpare}"></Run>
</TextBlock>
</DataTemplate>
</AutoSuggestBox.ItemTemplate>
</AutoSuggestBox>
For more about how to contact the string to display, set the display order and bind to ItemsSource please try it yourself. This depends on the original source and your special requirements.
I have the following XAML. The idea is to append the text " For Report" after a string that is coming from a bound XML file.
<GroupBox Header="{Binding XMLData.Element[HeadingText].Value}"
HeaderStringFormat="For Report">
When I add {0} to the beginning of the HeadingStringFormat String like so, the application ignores the HeaderStringFormat and simply puts up the databound value.
<GroupBox Header="{Binding XMLData.Element[HeadingText].Value}"
HeaderStringFormat="{0} For Report">
However, when I add a single space (or any other character for that matter) after the quote, but prior to the left {, the application works fine.
<GroupBox Header="{Binding XMLData.Element[HeadingText].Value}"
HeaderStringFormat=" {0} For Report" >
In the first example, the editor seems to think that the string (between the quotes) isn't a string anymore, but if I put in that space, it's happy.
Try prefixing your format string with {}. This should work:
<GroupBox Header="{Binding XMLData.Element[HeadingText].Value}"
HeaderStringFormat="{}{0} For Report">
For further information, see MSDN: {} Escape Sequence / Markup Extension
I have a TextBlock I would like to pass a property of 'LineSpacing'. The thing with using "LineHeight" with LineStackingStrategy="BlockLineHeight" is that it also applies the LineHeight to the segment before the first line:
How can I manage to preserve said 'LineSpacing' without modifying the LineHeight before the first line?
One thing I though might work is to separate each line in a Paragraph of a FlowDocument, since the Paragraph has a property Spacing Before Line and Spacing After Line.
Any help would be truly appreciated. Thanks in advance.
ANSWER
It seems that you can use LineStackingStrategy="MaxHeight" to avoid having leading on the first line. (Check answers below for full details).
P.S. Thanks to Mitch for the revelation :D
It seems that you can use LineStackingStrategy="MaxHeight" to avoid having leading on the first line:
<TextBlock LineStackingStrategy="MaxHeight" TextWrapping="Wrap" LineHeight="50">Lorem...</TextBlock>
Produces
I am trying to create custom menu which consists of text at least 2 textblock in one rectangle, which will act as button, For that purpose, May be converting the text into Image may be good idea to implement and serve my purpose to. so I want and Idea or code to create image during runtime, any suggestion ? If you have any sample code or link to refer??
if by "2 textblock in one rectangle" you mean text in two lines then try this
<Button>
<StackPanel>
<TextBlock Text="ABC"/>
<TextBlock Text="DEF"/>
</StackPanel>
</Button>
Is it possible in a Silverlight Datagrid to manually define where the line break should be? (instead of automatically wrapping to the next line when the border is reached)
This seems like to be the code (source):
<sdk:DataGridTextColumn
Header="Address"
Width="150"
Binding="{Binding Address}" >
<sdk:DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap"/>
</Style>
</sdk:DataGridTextColumn.ElementStyle>
</sdk:DataGridTextColumn>
But how do i manually make the line break?
It is possible in common WPF controls so I believe it should be possible on Silverlight as well. Basically what you need is to target the TextBlock control on each cell of the column, similarly to what is being done to give it a text wrapping style.
As you don't clarify from your question wheter you want to assign the text programmatically or on the XAML, I am going to give you a hint on how to do both.
You can assign the text programmatically using an approach similar to this answer:
txtBlock.Inlines.Add("This is the first paragraph");
txtBlock.Inlines.Add(new LineBreak());
txtBlock.Inlines.Add("This is the second paragraph");
On the other hand, if you want to assign the text directly on XAML, you can use the <LineBreak/> tag directly inside your text, as mentioned in this answer:
<TextBlock>
This is the first paragraph <LineBreak/>
This is the second paragraph
</TextBlock>