|
The breaking changes document points out that ContentPresenter now derives from FrameworkElement and thus loses 18 public properties as well as TextAlignment, TextDecorations and TextWrapping. All of this calls for a bit of rewriting if you've used this powerful and useful control, and there was a request in one of the internal discussion lists that this be called out to developers; hence this blog entry. Serendipitously, I have a video that uses the ContentPresenter control . The ContentPresenter control is the enabling control behind entering "Content" rather than text in the standard Button, CheckBox and so forth. Until RC0, you could have set the fontsize, FontWeight, etc. in the ContentPresenter itself, though that never would have been good programming practice, as it always made more sense to leave that for the client (the programmer using your control. Thus, in my template, I set few properties on the ContentPresenter itself, and when I use the control that the ContentPresenter is part of (the Button) I can set the characteristics of the content, which are then passed to the ContentPresenter. This will continue to work in RC0 Let me be explicit, if you used ContentPresenter as intended (note the Beta documentation which states "Typically, you use the ContentPresenter directly within the ControlTemplate of a ContentControl to mark where the content is to be added.") then you would probably not have used any of the properties that are no longer available to you, as you would have wanted, as I did, to leave that flexibility to the consumer of your control. On the other hand, if you did use those properties, the fix is fairly simple, you just remove the properties from the content control, and if you need the property set, you set it when you call the control An example will make this explicit. Assume you define your button template in App.xaml as follows (the following listing is abridged): 1: < ControlTemplate x:Key ="RoundButton" TargetType ="Button" > 2: < Grid > 3: < vsm:VisualStateManager.VisualStateGroups > 4: </ vsm:VisualStateManager.VisualStateGroups > 5: < Ellipse > 6: </ Ellipse > 7: < ContentPresenter Margin ="0,10,0,0" x:Name ="RoundButtonContent" 8: RenderTransformOrigin ="0.5,0.5" 9: HorizontalAlignment ="Center" 10: VerticalAlignment ="Center" 11: FontFamily ="Comic Sans MS"...
|