How to set main window invisible to display image as main window in WPF
I want to try to make a login screen for kids to login with only their names. I would like to use an image as a login screen, not a boring normal window. My only problem is that whenever I run it, there is still a border surrounding the image and when I set the main invisible window it also makes the image inside it invisible. In the image below you can see that there is still a gap around the image, even thought about its transparency and there are still borders around it, how can I get rid of this?
source to share
In your xaml window, set WindowStyle
to None
, from AllowsTransparency
to true
and from ResizeMode
to NoResize
.
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300"
ResizeMode="NoResize"
WindowStyle="None"
AllowsTransparency="True"
Background="{x:Null}">
<Grid>
...
</Grid>
</Window>
To move a window without borders use this code:
// In xaml
<Window ... MouseDown="Window_MouseDown">
// In code behind
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left) this.DragMove();
}
source to share
I think that one modification that you should add to @Dusan, in another correct answer, is that the Windows background must be transparent and the background image cannot be placed in the window, but in a child control (like in Grid
) :
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
WindowStyle="None"
AllowsTransparency="True"
Background="Transparent" >
<Grid>
<Grid.Background>
<ImageBrush ImageSource="C:\Users\Public\Pictures\Sample Pictures\Desert.jpg"/>
</Grid.Background>
</Grid>
</Window>
source to share