Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: WPF Programmer's Reference: Windows Presentation Foundation with C# 2010 and .NET 4
This is the forum to discuss the Wrox book WPF Programmer's Reference: Windows Presentation Foundation with C# 2010 and .NET 4 by ; ISBN: 9780470477229
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: WPF Programmer's Reference: Windows Presentation Foundation with C# 2010 and .NET 4 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 11th, 2010, 11:26 AM
Registered User
 
Join Date: Oct 2010
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default "ButtonResources" code display different in .NET3.5 and .NET4.0

The book is for C#2010 and .net 4.0 ,but the code i download from your website is target for .net 3.5.There are some inconveniences to convert the code from .net 3.5 to .net 4.0 in visual studio 2010.
The main code in this demo is following.
Code:
<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="ButtonResources.Window1"
    x:Name="Window"
    Title="ButtonResources"
    Width="540" Height="320"
    FontSize="16" FontWeight="Bold"
    Background="LightBlue">
    <Window.Resources>
        <BitmapEffectGroup x:Key="bmeButton">
            <DropShadowBitmapEffect/>
        </BitmapEffectGroup>
    </Window.Resources>
    <StackPanel Margin="5">
        <StackPanel Orientation="Horizontal"></StackPanel>
        <Button Width="218" BitmapEffect="{StaticResource bmeButton}" Height="65"></Button>
    </StackPanel>
</Window>
When I set the .NET target is .NET3.5, I can see its drop shadow effect ,but not in .NET4.0. Who can help me, please?
Reply With Quote
  #2 (permalink)  
Old October 12th, 2010, 01:03 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,145, Level: 23
Points: 3,145, Level: 23 Points: 3,145, Level: 23 Points: 3,145, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 641
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Sorry about that. I confess I cheated a little there. Expression Blend doesn't support Framework 4.0 yet and the older classes work better so I went with the older solution.

As you note, .NET Framework 4.0 flags BitmapEffects as obsolete. You're supposed to use the Effect class instead. So a button with a drop shadow would look like this:

<Button Width="218" Margin="10" Height="65">
<Button.Effect>
<DropShadowEffect/>
</Button.Effect>
</Button>


Unfortunately the only pre-defined Effect classes are DropShadowEffect and BlurEffect. If you want others, you need to derive them from ShaderEffect.

You can fake an outer glow by using a DropShadowEffect with ShadowDepth = 0 as in:

<Button Width="218" Margin="10" Height="65">
<Button.Effect>
<DropShadowEffect ShadowDepth="0" BlurRadius="20"/>
</Button.Effect>
</Button>


I don't know how to do others such as bevel and emboss, though.

I have also been unable to store an Effect as a resource as you're trying to do in your example, although I have been able to make a named or unnamed style that uses an Effect.

It seems to me that Microsoft has a bit more work to do here.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
The Following User Says Thank You to Rod Stephens For This Useful Post:
faunkyou (October 12th, 2010)
  #3 (permalink)  
Old October 12th, 2010, 10:13 PM
Registered User
 
Join Date: Oct 2010
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Thumbs up

Quote:
Originally Posted by Rod Stephens View Post
Sorry about that. I confess I cheated a little there. Expression Blend doesn't support Framework 4.0 yet and the older classes work better so I went with the older solution.

As you note, .NET Framework 4.0 flags BitmapEffects as obsolete. You're supposed to use the Effect class instead. So a button with a drop shadow would look like this:

<Button Width="218" Margin="10" Height="65">
<Button.Effect>
<DropShadowEffect/>
</Button.Effect>
</Button>


Unfortunately the only pre-defined Effect classes are DropShadowEffect and BlurEffect. If you want others, you need to derive them from ShaderEffect.

You can fake an outer glow by using a DropShadowEffect with ShadowDepth = 0 as in:

<Button Width="218" Margin="10" Height="65">
<Button.Effect>
<DropShadowEffect ShadowDepth="0" BlurRadius="20"/>
</Button.Effect>
</Button>


I don't know how to do others such as bevel and emboss, though.

I have also been unable to store an Effect as a resource as you're trying to do in your example, although I have been able to make a named or unnamed style that uses an Effect.

It seems to me that Microsoft has a bit more work to do here.
Thanks for your reply, I believe that you can do better in next edition.
Reply With Quote
  #4 (permalink)  
Old October 12th, 2010, 11:41 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,145, Level: 23
Points: 3,145, Level: 23 Points: 3,145, Level: 23 Points: 3,145, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 641
Thanks: 2
Thanked 96 Times in 95 Posts
Default

If I were writing a new edition right now I'd do about the same thing. Perhaps I'd add a paragraph or two explaining the situation but really Microsoft needs to fix this. It wasn't very nice of them to remove this functionality without providing a replacement.

However in all fairness, they usually don't do this sort of thing. They're usually pretty concerned about "breaking changes" as they call them.

Perhaps when Expression Blend 5 and .NET Framework 5 come out, whenever that may be, they will have fixed this.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Difficulties with "web.config" and "ASPNETDB" CFRham BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 2 July 3rd, 2010 11:19 AM
Need code corrections "get sub or function not defined" error" bluesboytoo Excel VBA 1 October 23rd, 2009 12:12 AM
How to theme the "Browse" button of "FileUpload" control? varunbwj BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 October 14th, 2009 02:22 AM
Add a CheckBox DataColumn to my DataGridView, Null format: "" or "True" but Error: F ismailc C# 2005 0 September 25th, 2009 05:56 AM
Code not going as planned: "icicle" vs "savedinstancestate" joopthecat BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 3 May 3rd, 2009 04:09 PM



All times are GMT -4. The time now is 03:39 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.