WPF C# - WindowChrome Resize Overlaping Button - c#

I have a window with a WindowChrome object and a UserControl full of buttons
<WindowChrome.WindowChrome>
<WindowChrome GlassFrameThickness="0,0,0,1" ResizeBorderThickness="2,0,2,2" />
</WindowChrome.WindowChrome>
<Objects:WindowButtons x:Name="WinButtons" Grid.Column="5" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,0,0,0" Grid.ColumnSpan="2"/>
I want to have a nice unbordered window while maintaining ease of controlling the size.
However the resize tool overlaps the buttons so I cannot click on it and I can only click on the bottom left of the button
How can I place the buttons above the resize dialog?

It sounds like you simply need to add this property to your button:
WindowChrome.IsHitTestVisibleInChrome="True"

Related

How to sync ui to full screen or compact mode using MediaPlayerElement

I'm using MediaPlayerElement, when my app window in normal size, I have a Button and a TextBox on the MediaPlayerElement. But when I click fullscreen or compact button to enter fullscreen or compact mode, they disappeared.
How to show them in full screen or compact mode?
A helpfull repo is here, sync the TextBox to fullscreen.
For your requirement, you could custom your MediaTransportControls and found ControlPanel_ControlPanelVisibilityStates_Border in the style. Then add your element under the that border.
For example
<Border x:Name="ControlPanel_ControlPanelVisibilityStates_Border">
<Grid>
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Top"
FontSize="25"
Foreground="Red"
Text="This is title"
/>
<Grid
x:Name="ControlPanelGrid"
VerticalAlignment="Bottom"
Background="{ThemeResource SystemControlPageBackgroundAltMediumBrush}"
RenderTransformOrigin="0.5,0.5"
......
I add the title TextBlock into the style.

wpf over activeX

I am trying to overlay buttons on a WindowsFormsHost that contains an activeX control embedding VLC. The issue I have is that activeX is always on top of wpf. Are there any ways to get a wpf control over the activeX control?
The VLC control also does not seem to support rendering to a bitmap.
I finally found a solution. The popup primitive is also an element that is always on top and can be placed over the vlc control. Its a bit of a hack, but it gets the overlay that I needed. My xaml for the player looks like this
<grid>
<WindowsFormsHost x:Name="Host"
Height="200"
Width="200" />
<Border x:Name="Anchor"
Height="0"
Width="0"
HorizontalAlignment="Left"
VerticalAlignment="Top" />
<Popup Width="{Binding ElementName=Host,Path=Width}"
Height="{Binding ElementName=Host,Path=Height}"
PlacementTarget="{Binding ElementName=Anchor}"
AllowsTransparency="True"
IsOpen="True">
<Border Background="#30808080"
Width="{Binding ElementName=Host,Path=Width}"
Height="{Binding ElementName=Host,Path=Height}">
<Button Content="Start"
Height="20"
Width="60"
Click="button1_Click"/>
</Border>
</Popup>
</grid>
The above puts a light grey transparent layer over the vlc player that contains a button. The above doesn't account for if the window is resized or moved, but the issue of putting something wpf over the control has been solved.
Short answer: No.
Extracted from MSDN:
In a WPF user interface, you can change the z-order of elements to
control overlapping behavior. A hosted Windows Forms control is drawn
in a separate HWND, so it is always drawn on top of WPF elements.
For the case of VLC, there is VideoLan.Net available at: http://vlcdotnet.codeplex.com/
which allows for video to be output to an Image.

WPF Popup like Windows Form

I would like to create a popup in wpf that behaves as windows form. I have manage to close the popup using [x] when it displays. I am stuck on how I can add functional minimize and maximize buttons feature.
here is how i achieved the first step: close button:
How to place close [x] in WPF popup
<Popup Name="myPopup" IsOpen="True">
<StackPanel>
<Label Background="AliceBlue" Foreground="Blue" HorizontalAlignment="Stretch" HorizontalContentAlignment="Right" MouseDown="mouse_DownHandled">
x
</Label>
<Label Name="myLabel" Content="This is a popup!" Background="AliceBlue" Foreground="Blue"/>
</StackPanel>
</Popup>
the mouse_DownHandled event closes the popup by setting isOpen=false
Any ideas?Thanks.
I see what you want. I think what you want is not a Popup Control but actually a WPF Window with a special style set in it.
Use the WindowStyle property to achieve this.
Use
<Window Name="myPopup" WindowStyle="SingleBorderWindow">
<StackPanel>
<Label Name="myLabel" Content="This is a popup!" Background="AliceBlue" Foreground="Blue"/>
</StackPanel>
</Window>
If you want to show this from the code, you can create create an instance of the view and call
window.Show()
Your window should look like this

Resize WPF application

Have tried searching google but I'm struggling to find an answer to this.
I have a basic WPF application with a few controls on. When I maximise the application the controls on the screen stay the same size and I get a lot of wasted space.
Is there a way to get the controls to grow and shrink dynamically with the size of the main window?
Kind Regards
Ash
Don't set a fixed Height and Width properties for your controls.
Instead set, horizontal and vertical alignment to stretch. And make sure your controls are contained inside an appropriate layout panel.
For example-
Fixed size grid:
<Grid Background="Red" Width="50" Height="50"/>
Dynamically expending grid:
<Grid Background="Red" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
what you need is not resize, it's called scaling (or zooming) ;-)
Read this article; the task is very trivial with WPF.
(used to be much more complicated in Windows Forms...).
UI Scaling (UI Zooming) with WPF
basically all you need to add to the XAML is this:
<ScaleTransform
CenterX="0" CenterY="0"
ScaleX="{Binding ElementName=uiScaleSlider,Path=Value}"
ScaleY="{Binding ElementName=uiScaleSlider,Path=Value}"
/>
after that you can use mouse wheel or a slider or any other way (like in your case detect form maximized), to modify the Value of the ScaleTransform.
Where there's a will, there's a way. You will have to do some work yourself however, WPF can't automagically decide for you exactly how you want the resizing to be done.
Some relevant sources:
Layout containers
Data Binding
You can use content decorator that can stretch and scale a single child to fill the available space - Viewbox .
http://www.wpftutorials.com/2011/04/wpf-viewbox.html
this is no problem. The behavior of your controls depends on the container you use and the Horizontal and Vertical Alignment. For Example, if you use a Grid, a TextBox and a Button with Horizontal and Vertical Alignment: Stretch and width and height auto, the Textfield and Button will grow and shrink dynamically.
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Grid x:Name="LayoutRoot">
<TextBox Margin="8,8,8,104.96" TextWrapping="Wrap" Text="TextBox" Height="auto" Width="auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
<Button Content="Button" Margin="8,0,8,8" VerticalAlignment="Bottom" Height="92.96" Width="auto" HorizontalAlignment="Stretch"/>
</Grid>
Use a resizable control like Grid and put all the controls in Rows/Columns. Also set HorizontalAlignment to stretch for each control.

How to rotate a WPF Window?

Is it possible to rotate a WPF Window by 45 degree, using xaml?
First question: Why do you want to rotate the whole window?
If you really need it:
You can't rotate the normal WPF window. See: Rotate Window
You will have to create a borderless window and provide a UI to it. See: WPF Non-Client Area Design Techniques For Custom Window Frames
For rotated window look:
Set:
AllowTransparency property to
true.
WindowStyle to None to
remove window chrome
Background
to Transparent
Include a border (or anything meaningful like rectangle, circle, ellipse, etc.) as content of the window and following properties of border:
white background (or any non-transparent color)
rotate transformation, and
smaller size (so as to fit when rotated within the window).
Border will provide the UI to your window.
Be aware of cavaets of creating own borderless window, as it requires you to provide the window interface like minimise, maximise, close buttons; and may require some unmanaged code.
Also, in sample code below, the border when rotated has to be kept within the bounds of the window, otherwise it (and your custom window) will be trimmed.
Sample code
<Window x:Class="CustomWindowStyle.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
AllowsTransparency="True" WindowStyle="None" Background="Transparent"
Title="MainWindow" Height="600" Width="600">
<Border BorderBrush="Green" BorderThickness="2" Background="White" Width="360" Height="360">
<Border.RenderTransform>
<RotateTransform Angle="-45" CenterX="180" CenterY="180"/>
</Border.RenderTransform>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="23" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Grid.Row="0" Content="X" Height="23" Width="23" Name="button1" HorizontalAlignment="Right" VerticalAlignment="Top" Click="button1_Click"/>
<Grid Grid.Row="1">
<!--Main window content goes here-->
<TextBlock Text="Main window content goes here" HorizontalAlignment="Center" />
</Grid>
</Grid>
</Border>
</Window>
As far as I know you can't rotate an entire window, but you could put everything inside the window into a custom control and apply apply a RenderTransform object to the custom control.
Example (somewhat simple):
http://www.codeproject.com/KB/WPF/TransformationsIntro.aspx
-- Dan

Categories