How do I implement a chromeless window with WPF? - wpf

I want to show a chromeless modal window with a close button in the upper right corner.
Is this possible?

You'll pretty much have to roll your own Close button, but you can hide the window chrome completely using the WindowStyle attribute, like this:
<Window WindowStyle="None">
That will still have a resize border. If you want to make the window non-resizable then add ResizeMode="NoResize" to the declaration.

Check out this blog post on kirupa.

<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="300" Width="300" WindowStyle="None" ResizeMode="NoResize">
<Button HorizontalAlignment="Right" Name="button1" VerticalAlignment="Top" >Close</Button>
</Window>

Related

Combo box flickering in Window 10 Touch screen

I am using a WPF Combobox in my Wpf application.
Following are my issue scenario:
1.Open combo box using touch
2.Touch on any item from drop down list
3.Combo box drop down list close after a flickering.
This issue is not there in mouse click.
I made AllowsTransparency="True" for windows
System Specification:
1.Windows 10
2.Visual Studio 2017
3.Unchecked "Enable press and hold for right clicking" in Pen and Touch setting
Following is my Xaml.code:
<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"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d" WindowState="Maximized" WindowStyle="None"
Title="MainWindow" Height="800" Width="800" Background="Transparent" AllowsTransparency="True">
<Grid>
<ComboBox Name="cb" Height="50" Width="50">
<ComboBoxItem>A</ComboBoxItem>
<ComboBoxItem>B</ComboBoxItem>
<ComboBoxItem>C</ComboBoxItem>
<ComboBoxItem>D</ComboBoxItem>
<ComboBoxItem>E</ComboBoxItem>
<ComboBoxItem>F</ComboBoxItem>
<ComboBoxItem>G</ComboBoxItem>
</ComboBox>
</Grid>
</Window>
Please help

WPF: Textblock text in Popup goes outside of the main window

In my example wpf app I've added one button and one popup to the window. The button is in the bottom right corner and the popup has set "PlacementTarget" property to it and "Placement" set to top. The popup consists of one very long textblock.
What I expect this popup will behave is not to go outside of the window and therefore automatically set his "HorizontalOffset" to the appropriate value, but the popup behaves against my intentions.
Here's my xaml file:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1" x:Name="window" x:Class="WpfApplication1.MainWindow"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:Converters x:Key="Converters"/>
</Window.Resources>
<Grid>
<Button x:Name="button" Content="Button" VerticalAlignment="Bottom" Width="75" HorizontalAlignment="Right"/>
<Popup Placement="Top" PlacementTarget="{Binding ElementName=button, Mode=OneWay}" IsOpen="True">
<TextBlock TextWrapping="Wrap" Text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" Background="White"/>
</Popup>
</Grid>
Do anyone know how to fix it?
I've read that this should be default popup behavior to take care of going out of the boundaries, but not in my case. Thanks in advance.
Have you tried to set the width of the Popup or Textblock ?
Sorry, I can't write this poor answer as a comment..

WPF window not minimizing/maximizing

I am a novice WPF programmer. My problem is as below.
I have a WPF application and on the home screen, when I click on the maximize button, it does not maximize the screen, instead repositions it to the top left column. If I increase/decrease the screen size through click and drag, the maximize button works just fine. The window properties are set up as follows:
<Window x:Class="MyApp.Home"
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"
mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
x:Uid="Window_Main"
x:Name="HomeWindow"
WindowStyle="None"
AllowsTransparency="True"
WindowStartupLocation="CenterScreen"
Margin="0"
BorderBrush="Transparent"
BorderThickness="0"
Title="Home"
MinWidth="1000" MinHeight="800"
ResizeMode="CanResizeWithGrip"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
SizeToContent="WidthAndHeight"
Visibility="Visible"
d:DesignHeight="1080" d:DesignWidth="1200">
The XAML for button is:
<Button x:Uid="btnRestore" x:Name="btnRestore" Height="20" Width="20" Style="{DynamicResource Control_WindowControlBoxStyle}" Margin="5,0,0,0" ToolTip="Toggle Restore" Click="btnRestore_Click" />
And the code for btnRestore_Click is simple:
private void btnRestore_Click(object sender, RoutedEventArgs e)
{
WindowState = WindowState.Maximized;
}
I am sure there must be some silly mistake that I am committing but not able to figure out what that is. Seems simple but caught me in spin. Any help would be appreciated.
You have SizeToContent="WidthAndHeight", which will make the window resize to whatever size the content in the Window is.
Either remove this property, or make sure first child of your Window tag doesn't have a size set

Add Icon for ToolWindow in WPF

How can I add an Icon for ToolWindow in WPF?
Just as
<Window x:Class="WPFApp.Account"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Accounting Information"
FontFamily="Calibri" FontSize="13"
WindowStyle="ToolWindow" ResizeMode="NoResize"
Width="600" Height="600">
I know that is old but I passed through the same problem now days and I decide to contribute a solution.
You can't use icon with the WindowStyle 'ToolWindow', but you can use 'SingleBorderWindow' and in property ResizeMode the value 'NoResize'. Now you have the same behavior of 'ToolWindow' but with icon.
Have you tried the Window.Icon property?

Enabling Scrollbar in WPF

I'm having a problem right now where my WPF application hides anything below the fold when the window is too small vertically. How can I use XAML to get a vertical scrollbar to appear for the entire app so the user can scroll to see the rest of the content?
Put a ScrollViewer inside your Window:
<Window x:Class="WpfApplication2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<ScrollViewer >
<!-- Window content here -->
</ScrollViewer>
</Window>

Resources