none
WPF app fails if AllowTransparency property is "true" RRS feed

  • Question

  • I've tried to use MS Expression Blend 1.0 under XP 64bit. Simple application made in Blend starts and then fails after 5-20 seconds.

     

    Application XAML code:

    <Window x:Class="WpfApplication1.Window1"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    x:Name="Window"

    Title="Window1"

    Width="640" Height="480" Opacity="1" AllowsTransparency="True" WindowStyle="None" Background="{x:Null}">

    <Grid x:Name="LayoutRoot">

    <Border Opacity="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Background="#FFD1D1D1" BorderBrush="#FF000000" BorderThickness="1,1,1,1" CornerRadius="6,6,6,6" x:Name="mainframe">

    <Border x:Name="header" VerticalAlignment="Top" Height="22" Background="#FF000000" CornerRadius="6,6,0,0"/>

    </Border>

    </Grid>

    </Window>

     

    If I change "AllowsTransparency="True"" parameter  to "False" it works fine (but window border appears), else it fails with exception:

    EventType clr20r3, P1 untitledproject2.exe, P2 0.0.0.0, P3 47a09860, P4 presentationcore, P5 3.0.0.0, P6 470bf9e0, P7 3d34, P8 45, P9 system.invalidoperationexception, P10 NIL.

     

    I ported project to VisualStudio and compiled. After startup all was the same and I got the exception:

    System.InvalidOperationException was unhandled
      Message="An unspecified error occurred on the render thread."
      Source="PresentationCore"
      StackTrace:
           at System.Windows.Media.MediaContext.NotifyPartitionIsZombie(Int32 failureCode)
           at System.Windows.Media.MediaContext.NotifyChannelMessage()
           at System.Windows.Interop.HwndTarget.HandleMessage(Int32 msg, IntPtr wparam, IntPtr lparam)
           at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
           at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
           at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
           at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
           at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
           at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
           at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
           at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
           at System.Windows.Threading.Dispatcher.TranslateAndDispatchMessage(MSG& msg)
           at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
           at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
           at System.Windows.Application.RunInternal(Window window)
           at System.Windows.Application.Run(Window window)
           at WpfApplication1.App.Main() in H:\VisualStudio projects\WpfApplication1\WpfApplication1\obj\Release\App.g.cs:line 0
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException:

    So, it seems like there is a bug with a transpagent window drawing in WFP. Is there a solution or update?
    Wednesday, January 30, 2008 4:28 PM

All replies

  • Did you set your window frame style to "None"?  I think you have to do this or it will crash as you are seeing.

    Wednesday, January 30, 2008 4:57 PM
  • Yes, I did, if you mean WindowStyle... Even more, in Blend it sets to None automatically when you set AllowsTransparency to True.

    Wednesday, January 30, 2008 5:13 PM
  • Could you please send the test project over to me for repro?

    Thanks
    Friday, February 1, 2008 4:15 AM
  • Have you tried to turn off hardware acceleration (I reckon on Windows XP 64, software acceleration will be used when rendering layered window) to see if the problem still exists? you can use the following code to turn off hardware acceleration:

    public partial class Window1 : Window
    {
    public Window1()
    {
    InitializeComponent();
    }

    protected override void OnSourceInitialized(EventArgs e)
    {
    base.OnSourceInitialized(e);
    HwndTarget target = PresentationSource.FromVisual(this).CompositionTarget as HwndTarget;
    if (target != null)
    {
    target.RenderMode = RenderMode.SoftwareOnly;
    }
    }
    }

    Tuesday, February 5, 2008 6:33 AM
  • FYI...

     

    I'm getting the same problem.  I tried your fix and it made no difference.

     

    Peter

    Thursday, February 14, 2008 5:05 AM