I'm developing an application and I want to display a colored border (not into a window) around the screen (Skype-like). I've searched all the day on the Internet but I didn't find anything.
EDIT
I've already tried this:
<Border BorderThickness="10" BorderBrush="Red">
into my XAML and it displays the border around the window, but I want it around the whole screen even if I minimize the window.
EDIT:
I don't want to have a border for my app but a red border around all the screen, i think there must exist a windows API that allows it.
you can do something like this
<Window x:Class="WpfApplication6.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" ResizeMode="NoResize">
<Border BorderThickness="2" BorderBrush="Blue" >
<Grid>
</Grid>
</Border>
</Window>
this will give u
When your window is minimized, it's minimal in size by definition. What you want is actually a maximized window when it is known as minimized by the OS?!
go to a big window size (equal the maximized state) when you handle the minimized event.
thin out your app window that only the border is visible, leaving the inner space for the desktop. To give you an idea what the idea is: click here (just an example to give the unusual shape) In your case, it would be a thin line - rectangulare shape.
us this, but change the color and thickness if you wish. If this wasn't what you were asking please develop your question further and give examples.
<Border BorderBrush="Black" BorderThickness="2">
Related
My main window backgrond color is Background="#005075" when the user click on some button some small window pops up, and then I'm chanching the main window opacity like Opacity="0.5", the problem is that it makes the background lighter, how do I make a dark opcity in wpf?
I do something similar a lot. The best way to do this is by having a couple of top-level grid's in your Window and work with those rather than the Window itself.
For example, Ill do something like this:
<Window x:Class="WpfApp9.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:WpfApp9"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<!-- Background grid with 100% opacity -->
<Grid Background="#005075"/>
<!-- main grid, which sits on top of the background grid -->
<Grid x:Name="MainGrid" Background="Transparent" Opacity="0.5">
<!-- Windows controls go here -->
</Grid>
</Grid>
</Window>
Opacity will not make it darker. What you can do is you can make some kind of panel which is stretched all over your main window, and has a black color and opacity of 0.2 or something like that, and mainly is hidden by default. And when you want to make the main window disabled you make that panel visible. This should solve your problem.
You can also use it as a loading panel, if you add some animation in center or something like this. So it will be over all of the content of your main window and will not allow the user to interact with your main window while it's disabled.
P.S. The black panel with opacity 0.2 should be positioned over all of the controls in main window
I made a WPF app (WindowStyle="None" hence no default windows buttons like exit, maximize, minimize)
It doesn't set the color (in my case, it's black) to the entire frame:
As you can see, there is a bit of white gap. (It's not a margin, I tested for this).
<Window x:Class="FancyGUI.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None"
Title="MainWindow" Height="250" Width="340"
Background="Black">
</Window>
You need ResizeMode="NoResize" in your window, otherwise there's a title bar shown (empty in your case), even if you set WindowStyle="None".
With WindowStyle="None" only:
(notice the blue "gap" as you call it on top... that's your white gap, just that my theme is blue)
With ResizeMode="NoResize":
(no gap, but can't resize the window now)
Or if you still want it to be resized (have the resize grip on it), but not show that title bar, set AllowsTransparency="True" and ResizeMode="CanResizeWithGrip":
(notice the grip for resizing on bottom right)
Note that having AllowsTransparency=true may have side effects. If any of those side effects is a problem to you, you can implement the resizing yourself by creating your own (black in your case) border and send the drag/resize messages. Expand on whether you need this or not and I'll show you how.
I'm noticing that the typical chrome is removed around the window.
I recreated the window with the code you provided and I see this:
Is there a resource file being referenced that may be affecting the window?
Also, you have Live Visual Tree running. Try clicking the middle button and then try clicking on the white bar. If you can select it, you should see it selected in the VS Live Visual Tree window.
Edit...
After seeing Jcl's post about the ResizeMode="NoResize" I gave it a try.
Sure enough, that's the secret.
Thanks Jcl!
I want to make a full screen WPF app that looks the same on all machines with different screen resoltion. I created my MainWindow.xaml with a 800*480 px resoultion. I made a menu on the top of the window like this:
<Grid Height="480" Width="800">
<Menu FontSize="25" Margin="0,0,0,442" >
<MenuItem Header="File" />
</Menu>
</Grid>
But when I started the app in Debug Mode, the menu was in the center of the screen. I guess it was because my screen resoultion is 1366*768 px.
So what should I do to make my program look the same on different resoultions in full screnn mode?
UPDATE: I want it to be like Photoshop for example. Photoshop looks almost the same on different resoultions. Images:
http://i.stack.imgur.com/W1SL6.png
http://i.stack.imgur.com/7KYxX.png
UPDATE : I just want to know what these values should be to make the program work like I want it to:
Height of Window,
Width of Window,
Height of Grid,
Width of Grid,
Sorry bros, I'm such a beginner :\
Another method is to use ViewBox:
<Viewbox StretchDirection="Both" Stretch="Uniform" />
For example:
<Window
Height="480"
Width="800">
<Viewbox StretchDirection="Both" Stretch="Uniform">
<Grid Height="480" Width="800">
</Grid>
</ViewBox>
</Window>
Now when you resize your window, all elements resize too.
It's not really going to be possible to make an application look exactly the same in every resolution. One of the problems with this is text - it's difficult to scale text in the same sense as you can a button, or a ListBox, or whatever.
But, one of the things you can do to make it so that your application looks substantially similar is to use relative positioning and sizing rather than absolute, as you are now.
I've rarely found it's useful or successful to use margins like the one you have above, where the Menu is offset by 400-some pixels. Typically, this ends up making your design look good only at the exact size at which you designed them. If you want this at the top of the control, you could do the following:
<Menu ... VerticalAlignment="Top" ...>
This would always have this menu aligned to the top of your Window. Likewise, if you wanted the menu to take up the same amount of relative vertical space in the window regardless of the absolute size of the window, you could use the Grid.RowDefinitions property:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="10*"/>
<RowDefinition Height="90*"/>
</Grid.RowDefinitions>
<Menu Grid.Row=0 />
</Grid>
This way, the Menu occupies the entire top row, and will consume 10% of the vertical space in the window regardless of resizing. There are some edge cases, obviously, particularly when controls get resized to the point where the text they contain cannot be seen anymore - if these are concerns you should use MinHeight and MinWidth on your Window or a specific control in order to provide a floor at which the control in question doesn't shrink anymore.
Note that, if you don't explicitly set the size of the Grid, it fills the entirety of its parent container by default - the entirety of the Window in this case. If you want your application to look the same, you can't give the parent Grid an absolute size like 800x480.
I want to have a WPF-Window that is shaped like an image. So basically I have an image that contains transparency and at the transparent places I just want to see through the window to my desktop. In the non-transparent places I want to see my image. Similar to what is done here, but in a way that is simple and understandable(in the example I linked there is LOTS of XAML and I don't understand a word).
Much of the XAML you see in that example is stuff unrelated to just showing a window that only shows the image. The rest of it is basically handling the minimize/maximize/close buttons.
To get you started, the below is all you really need to show a window that just has your image. You can then go from here and add buttons and things as needed, using that example XAML from the article to lead you on.
<Window x:Class="CSWPFIrregularShapeWindow.PictureBasedWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="PictureBasedWindow" Height="300" Width="300" Background="Transparent"
WindowStyle="None" AllowsTransparency="True" >
<Grid>
<Image Height="250" Name="test" Source="/CSWPFIrregularShapeWindow;component/Images/transparentPic.png"
Stretch="Fill" />
</Grid>
</Window>
I have a WPF Window defined in XAML like this:
<Window x:Class="com.some.company.window"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="My Cool Window"
x:Name="CoolWindow"
Height="435"
Width="70"
MinWidth="70"
MaxWidth="70"
Left="{PropertyState Default=0}"
Top="{PropertyState Default=0}"
Initialized="InitializeWindow"
ResizeMode="NoResize"
Style="{DynamicResource DefaultWindow}">
.....
.....
</Window>
The problem is that when the Window is created and displayed on the screen - it is ALWAYS larger than the 70 pixels I specified in the width definition. The width is probably 80-90 pixels. My width attributes are ignored. None of the contents inside the Window are larger than 70 pixels either.
Even when I try to resize the window with the grips, it will not let me resize it below a specific width. Is there some reason WPF is not letting me set the width of the window smaller? Is there a hidden minimum width value for every window? and how would I get around this?
EDIT:
When I add WindowsStyle="None" into the Window attribute, the width is correctly set to 70 pixels. However, this is not the style I want for the Window.
Thanks
You have set MinWidth to 70 and therefore size of your Window cant be less than that. BTW because of control box it's width seems to have a minimum limit of 132.
If we set WindowStyle="none" to remove the title and control box, we can make the Window even smaller.
<Window x:Class="WpfApplicationUnleashed.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:local="clr-namespace:WpfApplicationUnleashed"
Title="" WindowStyle="None" Width="70">
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
</Grid>
</Window>
EDIT
To make the Window width to 70, while the close button, Title text still visible and no-resize use this:
<Window x:Class="WpfApplicationUnleashed.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:local="clr-namespace:WpfApplicationUnleashed"
Title="My Window" WindowStyle="ToolWindow" Width="70" ResizeMode="NoResize">
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
</Grid>
</Window>
Since 70 is a very small width, you cant have minimize and maximize button along with close button.
70 that you have specified is not in pixels. WPF works on points and it actually sizes window to pixels based on Screen DPI (Dots per Inch).
I was able to do what I wanted by adding WindowStyle="ToolWindow" and ResizeMode="NoResize". This allowed me to keep the titlebar and the close button, while allowing the window's width to be set at 70pt.