Hi,

Have a look at the code. Try to guess

1. What color will be used to render text “Hello world” initially ?
2. Will it change after button click ?

Image

Answer:

Initially it will be yellow (yeah, it was easy). But after button click in WPF text color will change, but in SL for Windows Phone it won’t.

Explanation (actually not)

Basically i don’t understand this difference. I feel that this is a bug in Silverlight.
When we set foreground of a
1. ContentControl – the value gets inherited by TextBlockButton (TextBlockButton Foreground value is a new brush now), but notification is not sent to TextBlockButton template children (TextBlock) and TextBlock still uses old brush.
2. TextBlockButton – the notification is sent to its template children and text color changes.

Workaround:

Remove TemplateBinding for Foreground on TextBlock in ControlTemplate

Advertisements

One thought on “Funny difference in DP value inheritance between WP and WPF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s