WPF Button BitmapEffect Problem


  • I'm having all kinds of problems with WPF syntax issues. Here is one problem - I cannot set the BitMapEffect property of a Button in a Grid (underlined below).  If I remove that code, the app runs, if I leave it in it won't load the xaml page at all.  Any ideas?


    <Grid Margin="11.432,30,0,67.163" Name="grid2" ShowGridLines="True" HorizontalAlignment="Left" Width="211.492" Background="PaleGoldenrod">


    <RowDefinition Height="*"/>

    <RowDefinition Height="*"/>

    <RowDefinition Height="*"/>

    <RowDefinition Height="*"/>



    <ColumnDefinition Width="*" />


    <Label Grid.Row="0" Grid.Column="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"   Name="row1" Grid.ColumnSpan="1">Row 1</Label>

    <Image Grid.Row="1" Grid.Column="0" Name="image1" Stretch="Fill" HorizontalAlignment="Center" VerticalAlignment="Center" Source="/WpfBrowserApplication1;component/Resources/cheetah.gif" />

    <Label Grid.Row="2" Grid.Column="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Name="row3" Grid.ColumnSpan="1">Row 3</Label>

    <Button Grid.Row="3" Grid.Column="0" Name="button2" Background="CadetBlue">


    <BevelBitmapEffect />





    Saturday, April 19, 2008 7:42 PM


All replies

  • I can't see any issue in this. I didn't try with your code, but wrote similar code and the VS 2008 Designer as well Expression Blend 2.5 March preview both worked fine.


    What version are you working with? Also what error are you getting? In VS or in Expression usually you will get some indication of what is the reason why the designer isn't loading. Also is the error only with designer or at runtime as well?


    Tuesday, April 22, 2008 1:15 PM
  • I am using Visual Studio 2008 Standard Edition.  I had the same problem while using the Express edition.  It's a C# application.


     The error appears like this:


    Cannot create instance of 'Page1' defined in assembly 'WpfBrowserApplication1, Version=, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation.  Error in markup file 'Page1.xaml' Line 1 Position 7.


    But if i remove the BitmapEffect code, the error goes away. Obviously it doesn't fail on line 1 pf Page1.xaml... How do I debug something like this?




    Tuesday, April 22, 2008 2:34 PM
  • What I didn't mention is that the application is a web browser app, not a window app.  If I change the base type of the xaml from Page to Window, the code works just fine.  But I want a web page app.  Am i getting somewhere?

    Tuesday, April 22, 2008 6:07 PM

    I tried with regular window XAML, a Page.xaml inside of Windows application and also created a new browser application and added the code in it's Page1.xaml and it still worked fine. I can't reproduce the error.

    Wednesday, April 23, 2008 4:40 AM
  • You see this error when you F5 - correct? From what I recall Bitmap effects are not available in partial trust - you can't use them from Web Browser Apps. I'd suggest verifying that I'm right on the WPF forum http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=119&SiteID=1 



    Wednesday, April 23, 2008 5:23 PM
  • Now, when I simply create a new WPF Browser app and run it - it crashes.  What's going on here?  I can't imagine that Bitmap effects aren't available in a partial trust application.  And making it a full trust application doesn't result in any change.  And the link you sent me above doesn't go anywhere useful that I can see.


    Mark 2


    Friday, April 25, 2008 7:25 PM
  • I'd suggest you ask this question on the WPF forum. They'll know for certain




    Friday, April 25, 2008 11:38 PM
  • Good idea - here i go! (figuratively)


    Monday, April 28, 2008 9:46 PM
  • I have just installed VB-Express and given it a test run. I'm new to this and later versions of VB. I last used VB3 some time ago.  I had a similar problem, when trying to test the image control on the xaml web page test application. It worked fine without the graphics. As soon as I pointed the source to the local file system and then ran tha pplication, I got the same type of error.




    My solution was to change the image file source reference from a local file path, to a full http URL on my intranet, when I had copied the image file. It then worked fine !


    i.e. instead of Source: d:\TEST\MyImage.gif


    I used; http://mywebserver/test/MyImage.gif


    which woked fine !


    Thus I'm thniking that somehow the xaml application simply does not like referring to local file paths for the Image control Source property. At least in VB-Express.







    Monday, May 5, 2008 7:24 AM
  • i didn't have any problem displaying the image - it's just the BitmapEffect code that was not working.  But figuring out how to get the image to work wasn't obvious.  One way I found was to make it a resource, and I found that somewhere in the forums.


    Now my problem still remains - even after a re-install, a WPF browser app won't run.  Something seems to be messed up in the registry.  This seemed to happen after I installed the Windows Mobile 6 tools (I don't recommend it) only to find out that they don't work with Visual Studio Standard edition anyways.  So what do I do now?  Format C:?




    Monday, May 5, 2008 2:42 PM
  • The simplest way to set up an Image Source is as follows:


    - Add the bitmap to the project

    - Add an Image control to the designer

    - Use the Source property in the property browser to set the Source of the Image Control to the bitmap you just added


    I agree that the syntax for Image Source is arcane and so this is the easiest way to set it up.


    When you say your WPF browser app won't run, do you mean it won't run when you have the BitmapEffect in it? Does it run without the BitmapEffect?



    Monday, May 5, 2008 4:08 PM
  • When I originally started the post (see the first message) the app would run if I removed the BitmapEffect code, but otherwise would not run.  However, after I installed the Windows Mobile 6 tools (perhaps unrelated, but doubtful) I can no longer run ANY WPF Browser app, even with the default application you get when first creating a WPF Browser solution.  And PresentationHost crashes.  If I look closer at the crash messages I see complaints about not finding certain registry entries.  How could that be when I did a complete uninstall and re-install of VS2008 Standard? (I also uninstalled the CompactFramework stuff that Mobile 6 had installed).


    Monday, May 5, 2008 6:00 PM
  • Is it just WPF Browser applications or all WPF applications that crash?

    Monday, May 5, 2008 8:23 PM
  • Just WPF Browser.  I finally figured the crashing problem out.  I had messed up the code in app.xaml:




    It should have been:




    I'm not sure if this cause strange recursive behavior or what.


    Now my original problem is still there.  If I put a button in a grid and then set the button bitmapeffect to something (bevel) then the application won't run.


    Just adding this code to a button causes the problem:


    <Button Height="32" HorizontalAlignment="Right" Margin="0,0,19,19" Name="button1" VerticalAlignment="Bottom" Width="95" Background="CadetBlue" FontSize="14" Click="button1_Click">Push Me


    <BevelBitmapEffect />




    It runs fine without the BevelBitmapEffect code.


    The error is:


    Cannot create instance of 'Page1' defined in assembly 'WpfBrowserApplication1, Version=, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation.  Error in markup file 'Page1.xaml' Line 1 Position 7.

    Monday, May 5, 2008 10:45 PM
  • For some reason if I make the application Full Trust the BitmapEffect (Bevel) works.  I suppose there is a rational explanation for it, but I can't think of one.


    The end?


    Tuesday, May 6, 2008 12:14 AM
  • Bitmap Effects require Full Trust and XBAP applications only have Partial Trust.
    Michael S. Scherotter
    Wednesday, February 4, 2009 6:30 PM