How would you create nested block quotes in a FlowDocument? - xaml

I'm looking to do something like:
This is a block quote
This is a nested Block Quote
in a hand coded flow document. Currently I'm creating block quotes using:
<Paragraph Margin="10,0,0,0" BorderBrush="Silver" BorderThickness="5,0,0,0" Padding="10,0,0,0">
Block Quote
</Paragraph>
Since you can't nest a <Paragraph> inside another <Paragraph>, I'm at a loss for how to accomplish this.

Related

Xamarin Binding Special Characters

I am pulling some data from a remote DB and inserting them into a ResourceDictionary. My app will take the a key and get a value based on the chosen language.
My XAML looks like this:
<Label Text="{Binding Dictionary[, Something:]}"/>
<Label Text="{Binding Dictionary[" Why" - where what!]}"/>
So, if a user chooses Danish, the Label will use the key ", Something" and translate it to the Danish word.
The problem I'm having seems to be that I can't use special characters like "," and ":".
I have tried replacing those with Unicode and ASCII characters but it didn't work.

WinRT-xaml-Toolkit: Line Series with median Line

Is there a way to implement a median Line using this lib?
The only way I think could work is adding a new LineSeries and add a median for each Value in my Data-LineSeries
Something like this:
<charting:Chart>
<charting:Chart.Series >
<charting:LineSeries ItemsSource="{Binding Articles}" Title="Test Title" Height="400" Width="400" IndependentValuePath="dateTime" DependentValuePath="price" >
</charting:LineSeries>
---Pseudo----
<charting:LineSeries x:Name="Median" ItemsSource="{Binding Articles}" Title="Median" IndependentValuePath="dateTime" DependentValuePath="median">
</charting:LineSeries>
</charting:Chart.Series>
</charting:Chart>
This would cause me to add the median Value of my Product to each Article which is..kinda unnecessary.
Is there an easier way to do this? Or even a way which fills the space between Data and Median with a certain color (e.g. http://www.jidesoft.com/images/line-chart-gradient-fill.png)?
Thanks in Advance
I don't think there are any built in statistical functions in the DataVisualization library that I ported from Silverlight Toolkit, but you can provide your own data source separate from your Articles one that has any range of values you want.
I also can't recall if the filled style of the data series visualization is implemented, but you could try to create a modified version of the LineSeries one that does support Fill or check the source if any such property is already available. It might be doable by simply changing the Style of the series.

Multiple Colors In TextBlock

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 button certain characters change color?
Thank You. Any Help is appreciated.
Actually, you can, which can come in handy when you're doing a StringFormat on a data bound Textblock or a number of other places.
If you did want to try it though, like here's an SL example for a form label that puts a red asterisk next to the text Required Fields, but then can also add more stuff to it as shown in the example. Should work for Silverlight, WPF, UWP, etc...
<TextBlock>
<Run Text="*" Foreground="#FFE10101"/><Run Text="Required Line" />
<Run Text="Red" Foreground="Red"/>
<Run Text="Blue" Foreground="Blue"/>
<Run Text="{Binding SomeString, StringFormat='Hell ya you can make \{0\} a different color!'}" Foreground="Orange"/>
</TextBlock>
I'm developing for Mango with the WP7 SDK. You can use a <Run>. It seems a little buggy on WP7 , you have to add a spaces on the Run.Text property to get the spacing correct:
<TextBlock>Hello<Run Foreground="Bisque" Text=" Holla "></Run>and hello again!</TextBlock>;
to set foreground color dynamically to a textblock
use: txtblockname.Foreground= new SolidColorBrush(Colors.Yellow);
The TextBlock does not support multiple Foreground colors.
You could recreate this behaviour by using multiple textblocks (one for each letter) and placing them within a wrappanel. You could then change the color of individual characters/letters as you wish.
Beware of the probable performance impact this may have. The margins around individual letters will need to be adjusted to recreate standard behaviour though. Be especially careful around punctuation.

How to include an ampersand (&) in the content of a ComboBoxItem

I currently have a Combobox like the following:
//XAML
<ComboBox>
<ComboBoxItem> Awake & Alive</ComboBoxItem>
</ComboBox>
This raises an error:
Entity references or sequences beginning with an ampersand '&' must be terminated with a semicolon ';'.
I assume I am missing an escape sequence of some sort to allow me to use a &. How can I set the content of this comboboxitem to include a &?
Use & to encode the ampersand.
//XAML
<ComboBox>
<ComboBoxItem> Awake & Alive</ComboBoxItem>
</ComboBox>
The short answer is to use & to encode an ampersand.
See also Entities: Handling Special Content on XML.com:
At the lowest levels an XML parser is just a program that reads through an XML document a character at a time and analyzes it in one way or another, then behaves accordingly. It knows that it's got to process some content differently than other content. What distinguishes these special cases is the presence of such characters as "&" and "<". They act as flags to the parser; they delimit the document's actual content, alerting the parser to the fact that it must do something at this point other than simply pass the adjacent content to some downstream application.
... So one way to get around your immediate problem is to replace the ampersand in your content with the appropriate entity reference: <company>Harris & George</company>.
Alternatively, you can use the CDATA tag around the contents of the ComboBoxItem element; I think it better maintains the text's readability.
//XAML
<ComboBox>
<ComboBoxItem><![CDATA[Awake & Alive]]></ComboBoxItem>
</ComboBox>
For reference: http://www.w3schools.com/xmL/xml_cdata.asp

Writing XML Exactly as XML Literals are Written

I'm transforming some XML from DrawingML to XAML. Unfortunately, the XAML one is not working as expected with white spaces, but I have found a work around. Here's the problem:
Problem Statment
I want to write the following in a TextBlock:
Hi John, what did Sushi A say to
Sushi B?
So I would write:
<TextBlock>
<Run>Hey</Run>
<Run FontWeight="Bold">John</Run>
<Run>,</Run>
<Run FontStyle="Italic">what did Sushi A say to Sushi B?</Run>
</TextBlock>
This doesn't produce the desired results. Instead, it produces:
Hi John , what did Sushi A say to
Sushi B?
Notice the space now between "John" and ","? Weird, eh? This is because XAML appends a space between runs. I don't know why it does this. I really do need the formatting exactly as above, so the option of changing formatting, like making the comma bold too is not an option.
Partial Solution
The weirder thing is that there is a way around this - i.e. to lose the extra space that XAML adds - you have to put your runs on the same line. I have no idea why, but that's the case. So the following actually works just fine:
<TextBlock>
<Run>Hey</Run>
<Run FontWeight="Bold">John</Run><Run>,</Run>
<Run FontStyle="Italic">what did Sushi A say to Sushi B?</Run>
</TextBlock>
Notice runs #2 and #3 (of 4 runs) are now on the same line.
Question
The issue I'm having is that I haven't found a way to write the above using XML Literals. If I try this:
Dim tb = <TextBlock>
<Run>Hey</Run>
<Run FontWeight="Bold">John</Run><Run>,</Run>
<Run FontStyle="Italic">what did Sushi A say to Sushi B?</Run>
</TextBlock>
it is always created as the below, with the 4 runs on seperate lines:
<TextBlock>
<Run>Hey</Run>
<Run FontWeight="Bold">John</Run>
<Run>,</Run>
<Run FontStyle="Italic">what did Sushi A say to Sushi B?</Run>
</TextBlock>
Does anyone know how XML can be written exactly as written in XML Literals?
Bonus
If you answer the question correctly, I'll tell you the punchline of the joke :)
I don't suppose using a span will help you (as it will keep non-formatted text out of XML elements so it might not get auto-formatted).
i.e.
<TextBlock>
<Span>
Hey
<Bold>John</Bold>,
<Italic>what did Sushi A say to Sushi B?</Italic>
</Span>
</TextBlock>
Obviously this only fixes the specific case not the general, I would probably suggest not using XML literals :)
Any chance the unicode backspace character would solve your problem?
http://www.fileformat.info/info/unicode/char/0008/index.htm
Update
One other idea. Have you looked into the XDocument.Save(TextWriter textWriter, SaveOptions saveOptions) method? The documentation says that if you use SaveOptions.DisableFormatting, it will preserve spacing.