C# WPF Displaying WebBrowser on window with AllowTransparency=”true” does not display

cwebbrowser-controlwpf

I am displaying a window with a WebBrowser control on it.
I want the windows to be frameless so I have set WindowStyle="None"
This works BUT displays a colored border around the window.
Allowstransparency="true" removes this BUT the WebBrowser is no longer displayed (buttons are)

I have found http://www.neowin.net/forum/topic/646970-c%23-wpf-window-with-transparency-makes-windowsformshost-disappear/ BUT I cannot get it to work (SetWindowsLong Parameter error)

Window x:Class="ZoomBrowserWPF.WebWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:UMenu"
        Title="Test" Height="605" Width="700" ResizeMode="CanResizeWithGrip"
        Loaded="Window_Loaded" Unloaded="Window_Unloaded"
        WindowStyle="None"        
        Background="Transparent"              
        Left="1" Top="1"
        UseLayoutRounding="True" SizeChanged="Window_SizeChanged" >
    <Border Name="WindowBorder"  BorderBrush="Black" BorderThickness="1" CornerRadius="10"     Background="Beige">
    <Grid>        
        <Grid.RowDefinitions>
            <RowDefinition Height="25"/>
            <RowDefinition Height="30"/>
            <RowDefinition/>
            <RowDefinition Height="33"/>
            <RowDefinition Height="25.5"/>
        </Grid.RowDefinitions>
        <Grid x:Name="GridWebBrowser" Grid.Row="2" Grid.RowSpan="2">            
            <WebBrowser x:Name="webBrowser"  Grid.ColumnSpan="2" Visibility="Visible"
                         Margin="0,0,-16,0" 
                        ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                        ScrollViewer.VerticalScrollBarVisibility="Auto" 
                        ScrollViewer.IsDeferredScrollingEnabled="False"
                        ScrollViewer.CanContentScroll="False"
                        />
        </Grid>
        <Button x:Name="btnZoomIn" Content="Zoom in" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="12,0,0,0"  VerticalAlignment="Top" Width="75" Click="btnZoomIn_Click" />
        <Button x:Name="btnZoomOut" Content="Zoom out" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="168,0,0,0"  VerticalAlignment="Top" Width="75" Click="btnZoomOut_Click" />
        <TextBlock Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="102,0,0,0" Name="txtZoom" Text="100" VerticalAlignment="Top" Width="60" />
    </Grid>
    </Border>
</Window>

Best Answer

I know this is an old question but I had exactly the same problem today and I solved it using

ResizeMode="NoResize"

instead of

Allowstransparency="true"

The ResizeMode does remove the annoing border too and does not impact the WebBrowser control. Seems to be the easiest way to solve your problem in this case :)

Related Topic