Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 11th, 2010, 10: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?
 
Old October 12th, 2010, 12:03 PM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
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!)
The Following User Says Thank You to Rod Stephens For This Useful Post:
faunkyou (October 12th, 2010)
 
Old October 12th, 2010, 09: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.
 
Old October 12th, 2010, 10:41 PM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
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!)





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 10:19 AM
Need code corrections "get sub or function not defined" error" bluesboytoo Excel VBA 1 October 22nd, 2009 11:12 PM
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 01:22 AM
Add a CheckBox DataColumn to my DataGridView, Null format: "" or "True" but Error: F ismailc C# 2005 0 September 25th, 2009 04: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 03:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.