Changes to Annotations in Beta 2
Woo-hoo Beta 2 was released publicly yesterday! If you are using some of the samples from my previous posts than there are some breaking changes (and a few bugs) that you should be aware of. In the interest of keeping my blog short and informative I’ll cut right to the chase:
You can now control highlight opacity
You probably didn’t notice, but in previous versions the opacity of your highlights was always a constant .2. This meant that when we passed a static Brush with default opacity of 1, it will magically appear transparent in your document. This also meant that if you wanted to customize the transparency of certain colors you were unable to do so. As of Beta 2, we will respect whatever opacity you have defined in the brush that is passed in. This is good news because the desired opacity for Pink probably not be the same as for Black, so now you can adjust it to your personal liking. The impact is that if you simply pass a static system Brush as your highlight color, your highlight will be completely opaque. Lets look at how to convert our Yellow highlight from my previous posts to behave properly in Beta 2.
The color value of Brushes.Yellow is “#FFFFFF00”. Note that the first 2 bytes control the opacity, so its opacity is 1. In order to have a semi transparent highlight I’ll have to create a new SolidColorBrush and set its color to have an opactity of less than 1. First I’ll declare a new SolidColorBrush in the ResourceDictionary of my tree root:
<Grid.Resources>
…
<SolidColorBrush x:Key="YellowHighlightColor" Color="#54FFFF00"/>
…
Then I’ll pass this brush as my CommandParameter instead of the system Brush:
<Button Background="Yellow"
…
CommandParameter="{StaticResource YellowHighlightColor}"/>
Following the example above it should be straight forward how to go through and create a SolidColorBrush for each highlight color, customizing the opacity for each one.
Namespace Consolidation
The annotation schema changed a little, we consolidated and cleaned up the namespaces that were used. The result is that a Beta 2 app cannot read annotations created by a pre-Beta 2 app. If you are affected by this change, feel free to contact me directly for information about how to port your annotations to the new schema.
Known issues to watch out for
· If you are running on Vista, the toolbar outlined below will crash with a NullReferenceException from ButtonChrome.cs when you try and create or delete an annotation. This is a general theme issue with buttons executing commands which change from enabled to disabled while IsMouseOver==true. The simplest workaround for this demo is to place all the buttons directly inside the Toolbar (e.g. remove all GroupBox and StackPanels in the example). This will cause the ToolBar to override the default style of the buttons, shortcircuiting this bug.
· Printing annotations on FlowDocuments doesn’t work in Beta 2 (an exception will be thrown from the XPSWriter). There is no workaroundL, but it will be supported in later releases.
· Printing annotations made on an XPSDocument to the Vista XPS Document Writer will succeed but annotations will be ignored, annotations should appear when sent to any other printer. This specific scenario is something we hope to support for V1.
Hope that this helps someone outJ. If you notice that I’ve missed something or have questions please feel free to contact me.