I want to make an application with transparent window. I want to put one picture at the background of this window and make window transparent for inputs (i.e. if I click at window, it will be same as if I click there at screen if there is no this application). I want to make input box at application startup for input alpha. Is it possible to make an application like this one in c#? If yes, what is the best way to do this?
You can create a transparent window by the below XAML code in a WPF application. You can vary the opacity values between 0 and 1 to get the desired transparency. To get full transparency use 0.
<Window x:Class="WpfApplication3.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"
AllowsTransparency="True" WindowStyle="None" IsActive="False">
<Window.Background>
<SolidColorBrush Opacity="0.5" Color="White"/>
</Window.Background>
<Grid>
<TextBox Width="200" Height="50"/>
</Grid>
</Window>
Related
I have this window and I would like to resize content ( fit it to the size of window ) when the user maximize this window , I've tried many solutions but any of them worked for me :
<Window x:Class="Window_Image"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="550" d:DesignWidth="550">
<Grid>
<DockPanel LastChildFill="True" Name="ImgDock" Background="Transparent" >
<Image Source="../res/myimage.png" Width="450" Height="450" x:Name="ImageComp" Visibility="Visible" >
</Image>
</DockPanel>
</Grid>
One of solution that I've tried :
https://stackoverflow.com/a/47990733/19442413
Unfortunatly , this solution didn't works for me.
The issue was that the Image size was hardcoded (Height and Width properties).
By default, most of WPF's component will adjust their size to fill their containers.
Have this simple XAML for a custom window. It works fine except during a resize (from the left, top, top-left and bottom-left) it looks awful. The window flashes like crazy. Doesn't seem like an OS issue as Microsoft's glass Windows app resize smooth as butter.
I'm trying to customize the window frame, but unless I use WindowChrome, I lose all the resizing, dragging, etc.
<Window x:Class="WpfApp2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp2"
WindowStyle="None"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
Title="MainWindow" Height="450" Width="600">
<WindowChrome.WindowChrome>
<WindowChrome GlassFrameThickness="1,1,1,1" />
</WindowChrome.WindowChrome>
<Border BorderBrush="Red" BorderThickness="1">
<Button Content="Test" Height="25" Width="75" />
</Border>
</Window>
I am using the WPF Shell Integration library in my WPF project to provide shell functionality in my borderless form. I am wondering how I can stop the form from being resized, but retain the forms ability to move and keep it's shadow? To create the form I am simply adding this to my XAML.
<shell:WindowChrome.WindowChrome>
<shell:WindowChrome
ResizeBorderThickness="6"
CaptionHeight="10"
CornerRadius="0"
GlassFrameThickness="1">
</shell:WindowChrome>
</shell:WindowChrome.WindowChrome>
Simply add ResizeMode="NoResize" to the windows properties.
your xaml should look like this:
<Window x:Class="BorderLess.WindowBorderLess"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
ResizeMode="NoResize" >
<WindowChrome.WindowChrome>
<WindowChrome
ResizeBorderThickness="6"
CaptionHeight="10"
CornerRadius="0"
GlassFrameThickness="1">
</WindowChrome>
</WindowChrome.WindowChrome>
<Grid>
</Grid>
Is it possible to hide the default resize grip in wpf, I have a custom window without handles on the sides and are currently using:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="100" Width="200" ResizeMode="CanResizeWithGrip">
<Grid></Grid>
</Window>
I know it's possible to just change ResizeMode="CanResize" but this is the only way to resize the window that I can think of.
Yes you can take out the default resize grip from the Window. You need to override the WindowTemplate. Here is how you would do in XAML:
<Window x:Class="MyNamespace.MyWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None"
ResizeMode="CanResizeWithGrip"
AllowsTransparency="True">
<Window.Template>
<ControlTemplate>
<Border>
</Border>
</ControlTemplate>
</Window.Template>
</Window>
Within the "Border" will go everything that you need to display in the Window (e.g. a TextBox). Then if you want your custom ResizeGrip you can define that as well. Hope this helps.
I'm learning WPF on my own and I can't seem to find a way to make this work.
Here's my code:
<Window x:Class="Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Test" Height="600" Width="800" >
<DockPanel>
<Menu DockPanel.Dock="Right"
Height="30"
VerticalAlignment="Top"
Background="#2E404B"
BorderThickness="2.6">
<Menu.BitmapEffect>
<DropShadowBitmapEffect Direction="270" ShadowDepth="3" Color="#2B3841"/>
</Menu.BitmapEffect>
</Menu>
</DockPanel>
How can I make a tiled background image appear?
Set the ViewportUnits to absolute, which will allow you to define the pixel size of your image in the Viewport. In my example the image size is 32x32.
<Window.Background>
<ImageBrush ImageSource="image.png" TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,32,32"/>
</Window.Background>
Or, perhaps, you could use Visual Brush:
<Window
x:Class="Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Test" Height="600" Width="800">
<Window.Background>
<VisualBrush TileMode="Tile" Viewport="0,0,0.5,0.5">
<VisualBrush.Visual>
<Image Source="image.png"></Image>
</VisualBrush.Visual>
</VisualBrush>
</Window.Background>
</Window>
The Viewport property sets the position and dimensions of the base tile. Have a look at examples here.
Basically, "0,0,0.5,0.5" means that the base tile will take space from point (0,0) to (0.5,0.5) - i.e. from the upper left corner of the output area to centre. (1,1) is the lower right corner. You should make use of MSDN Library. It's really useful. All the answers are there.