I would like to change background opacity (make it darker) when programs starts
<Window x:Class="PCSX4.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:PCSX4"
mc:Ignorable="d"
Title="MainWindow" Height="900" Width="900"
WindowStyle="None"
WindowStartupLocation="CenterScreen"
Background="Transparent">
<WindowChrome.WindowChrome>
<WindowChrome GlassFrameThickness="0,0,0,1" CornerRadius="0" />
</WindowChrome.WindowChrome>
<Grid>
<Border Background="lightBlue" />
<Image HorizontalAlignment="Center" Height="1002" VerticalAlignment="Center" Width="900" RenderTransformOrigin="-2.3,-0.484" Source="/background.png" Stretch="Fill"/>
</Grid>
</Window>
Haven't tried anything because I don't know how to solve this problem as I'm new to this.
Related
I want to make my Grid with round corner in my WPF project.
And due to some reason, I have to use ViewBox and hence to make it more difficult.
My code is as below:
<Window x:Class="WpfApp5.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:WpfApp5"
mc:Ignorable="d"
WindowStyle="None"
AllowsTransparency="True"
Background="Green"
Width="500" Height="300">
<Grid x:Name="gridTotal">
<Viewbox x:Name="vb">
<Grid Width="500" Height="300">
<Image x:Name="BlackMaskImage" Stretch="UniformToFill"/>
<Button Width="100" Height="100">
</Button>
</Grid>
</Viewbox>
</Grid>
I tries some method, like this:
How can I make a rounded-corners form in WPF?
But not work for my case.
Moreļ¼
In my code, there are two Grid. But for me, the final appearance of the window has 4 round corner is OK. That is I don't care which Grid is fabricated.
I tried to change the gridTotal to a Border, and that border can own round corner. But its content is still a rectangle with sharp right angle.
In UWP, a Grid can apply Style with setter to set its CornerRadius, but in WPF I cannot do so.
You don't specify any region breakdown in the Grid.
Use Border instead.
<Window x:Class="WpfApp5.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"
mc:Ignorable="d"
WindowStyle="None"
AllowsTransparency="True"
Background="{x:Null}"
Width="500" Height="300">
<Border x:Name="gridTotal" CornerRadius="20"
Background="Green">
<Grid Width="500" Height="300">
<Image x:Name="BlackMaskImage" Stretch="UniformToFill"/>
<Button Width="100" Height="100">
</Button>
</Grid>
</Border>
</Window>
I have the following code to fit the grid exactly to the window.
As you can see in the screenshot, the grid is running out of the window on the bottom and right side. Do you guys have any idea why this is happening? and how to do it properly?
<Window x:Class="WpfApp1.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"
mc:Ignorable="d"
Topmost="true"
Background="Aqua"
WindowStartupLocation="CenterScreen"
DataContext="{Binding Main, Source={StaticResource Locator}}"
Title="MainWindow" Height="500" Width="500">
<Grid
Width="{Binding ActualWidth, RelativeSource = {RelativeSource AncestorType = {x:Type Window}}}"
Height="{Binding ActualHeight, RelativeSource ={RelativeSource AncestorType = {x:Type Window}}}">
<Border Opacity=".9" BorderBrush="Blue" BorderThickness="2"/>
</Grid>
</Window>
If you bind the actual widths and heights of the window, the Grid will exceed the Window, as the content area is smaller than the window itself. Remove the bindings. The Grid will be sized automatically to occupy the available space if you do not explicitly set a Width and Height.
<Window x:Class="WpfApp1.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"
mc:Ignorable="d"
Topmost="true"
Background="Aqua"
WindowStartupLocation="CenterScreen"
DataContext="{Binding Main, Source={StaticResource Locator}}"
Title="MainWindow" Height="500" Width="500">
<Grid>
<Border Opacity=".9" BorderBrush="Blue" BorderThickness="2"/>
</Grid>
</Window>
I am doing one wpf app using Modern Metro UI,i want context menus on this app
as i tried
<Controls:MetroWindow x:Class="Something" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:Dialog="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title=""
Width="326.478"
Height="5" ShowIconOnTitleBar="True" ShowTitleBar="True"
WindowStartupLocation="CenterScreen"
GlowBrush="{DynamicResource AccentColorBrush}"
mc:Ignorable="d" ResizeMode="CanMinimize" Loaded="MetroWindow_Loaded" >
<Controls:MetroWindow.Resources>
<ContextMenu x:Key="MyContextMenu">
<MenuItem Header="Send" />
</ContextMenu>
</Controls:MetroWindow.Resources>
<Grid>
</Grid>
</Controls:MetroWindow>
I am trying to add Context Menu to Wpf application which uses Modern Metro UI
A context menu should be declared within the actual element:
<Controls:MetroWindow x:Class="Something" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:Dialog="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title=""
Width="326.478"
Height="5" ShowIconOnTitleBar="True" ShowTitleBar="True"
WindowStartupLocation="CenterScreen"
GlowBrush="{DynamicResource AccentColorBrush}"
mc:Ignorable="d" ResizeMode="CanMinimize" Loaded="MetroWindow_Loaded" >
<Grid>
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="Send" />
</ContextMenu>
</Grid.ContextMenu>
</Grid>
I'm new to VS 2012, and I have this issue every time I use the XAML Designer.
Every time I add an item (e.g. a RadioButton, and Image, a Label) to my window, it deletes the previous one.
As a result, I can have only one item in my window, I know it is absurd, what am I missing?
Here is the xaml of the window
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WpfViewers="clr-namespace:Microsoft.Samples.Kinect.WpfViewers;assembly=Microsoft.Samples.Kinect.WpfViewers" xmlns:Toolkit="clr-namespace:Microsoft.Kinect.Toolkit;assembly=Microsoft.Kinect.Toolkit" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="KinectSetupDev.MainWindow"
Title="MainWindow" Height="400" Width="600">
<Toolkit:KinectSensorChooserUI x:Name="SensorChooserUI" VerticalAlignment="Center" Height="40" Margin="277,2,275,328"/>
</Window>
Here is the xaml of the window after dragging an image on it (from the Toolbox)
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WpfViewers="clr-namespace:Microsoft.Samples.Kinect.WpfViewers;assembly=Microsoft.Samples.Kinect.WpfViewers" xmlns:Toolkit="clr-namespace:Microsoft.Kinect.Toolkit;assembly=Microsoft.Kinect.Toolkit" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="KinectSetupDev.MainWindow"
Title="MainWindow" Height="400" Width="600">
<Image HorizontalAlignment="Left" Height="86" Margin="77,188,0,0" VerticalAlignment="Top" Width="111"/>
</Window>
As made clear by #Hans, I was trying to add multiple content items into a Window, in the XAML designer. This is just not possible so i had to:
1) Add a Grid to the Window.
2) Add any item to the grid.
It works, here is a sample code:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WpfViewers="clr-namespace:Microsoft.Samples.Kinect.WpfViewers;assembly=Microsoft.Samples.Kinect.WpfViewers" xmlns:Toolkit="clr-namespace:Microsoft.Kinect.Toolkit;assembly=Microsoft.Kinect.Toolkit" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="KinectSetupDev.MainWindow"
Title="MainWindow" Height="768" Width="1024" Loaded="Window_Loaded_1">
<Grid HorizontalAlignment="Left" Height="736" VerticalAlignment="Top" Width="1012" Margin="2,2,0,0">
<Image x:Name="Image01" HorizontalAlignment="Left" Height="240" Margin="136,27,0,0" VerticalAlignment="Top" Width="320"/>
<TextBlock x:Name="tbMessages" HorizontalAlignment="Left" Height="60" Margin="10,606,-664,-426" TextWrapping="Wrap" VerticalAlignment="Top" Width="974"/>
<WpfViewers:KinectColorViewer HorizontalAlignment="Left" Height="240" Margin="666,0,-666,0" VerticalAlignment="Top" Width="320"/>
</Grid>
</Window>
I have the following for the main window
<Window x:Uid="Window_1" x:Class="App1.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" Loaded="Window_Loaded" Closing="Window_Closing"
SizeChanged="Window_SizeChanged" Topmost="True" AllowsTransparency="True" Opacity="1"
WindowStyle="None" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen"
WindowState="Maximized" KeyDown="Window_KeyDown" MouseDoubleClick="Window_MouseDoubleClick" Background="Black"
MouseLeftButtonDown="Window_MouseLeftButtonDown" MouseMove="Window_MouseMove" >
<Viewbox x:Uid="Viewbox_1" Stretch="Uniform" StretchDirection="Both" SnapsToDevicePixels="True" >
<Grid x:Uid="MainLayout" Name="MainLayout" SnapsToDevicePixels="True">
<Canvas x:Uid="MainCanvas" Name="MainCanvas" SnapsToDevicePixels="True">
</Canvas>
</Grid>
</Viewbox>
but somehow in the NORMAL mode of the window some padding appears (It is black because of the window Background color)
Any clue how to take it out?
On your root window: Background="Transparent"
I tried to duplicate your problem, but without the full code, it doesn't seem to happen. I used this code:
<Window x:Class="WpfApplication2.MainWindow"
x:Uid="Window_1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Topmost="True" AllowsTransparency="True" Opacity="1"
WindowStyle="None" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen" Background="Black" >
<Grid Background="Green">
<Viewbox x:Uid="Viewbox_1" Stretch="Uniform" StretchDirection="Both" SnapsToDevicePixels="True" >
<Grid Background="Red" x:Uid="MainLayout" Name="MainLayout" SnapsToDevicePixels="True">
<Canvas x:Uid="MainCanvas" Name="MainCanvas" SnapsToDevicePixels="True" Background="Blue">
</Canvas>
</Grid>
</Viewbox>
</Grid>
</Window>
Just to see what would happen. Obviously without the image, the inner canvas, grid and viewbox don't take up any space and so all you get is a solid Green window (with the Green from the main Grid completely overlapping the Black of the Window).
My only thought is: Could it have something to do with the aspect ratio of your image versus the aspect ratio of your window when the Viewbox is using Uniform stretching?