Displaying wpf content over/outside main window bounds [closed] - c#

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am trying to achieve an effect of overlapping the main window boundary with a control. It's hard to explain this in words which is also maybe why I am having difficulty finding information on how to do this or if it is even possible.
Below is an example of the effect I am trying to get (from the designer), where the "note" objects float outside the bounds of the main window.
However the effect I get at runtime is this (below), the inner controls are clipped by the boundary of the main window.
Can someone please tell me if this is possible (or not), and if it is maybe some suggestions about how I could get this effect.

There is a control that can achieve this kind a behavior have you tried a Popup control?
Check this out
Here's an examp;e"
<Window x:Class="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">
<Grid>
<ToggleButton x:Name="MainButton" Content="Show popup" VerticalAlignment="Top" HorizontalAlignment="Right"/>
<Popup PlacementTarget="{Binding ElementName=MainButton}" Placement="Bottom" AllowsTransparency="True" IsOpen="{Binding ElementName=MainButton, Path=IsChecked}">
<Grid>
<Border BorderBrush="Orange" BorderThickness="1" Background="Yellow"/>
<TextBlock Text="Lorem Ipsum is simply dummy text of the printing and typesetting industry"/>
</Grid>
</Popup>
</Grid>

Contents of window will always get clipped. So basically there is only one way to go here. You could get the desired effect by creating a new transparent window for your floating content and then manualy set and update the position of floating content window based on the location of main window.
So far I've been using AvalonDock for similar functionalty. You might give it a try...

I don't think there's a way to draw outside the bounds of a window. However, you could simply create a new window for the note control and align it to your main window.

Did you try ClipToBounds property?

Related

On Windows 10 (1803), all applications lost touch or stylus if a WPF transparent window covers on them

If I create a new WPF application with a simple empty window like the code shown below, I find that all applications which are covered by the WPF app lost touch or stylus reaction. This can only be reproduced when Windows 10 is upgraded to 1803 (10.0.17134.0).
<Window x:Class="TheWPFCoveringWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None" WindowState="Maximized"
AllowsTransparency="True" Background="Transparent"
Topmost="True">
<Button Content="Test" Width="200" Height="100" />
</Window>
I wrote another WPF application to find out what happened. So I add a StylusDown event to the Window like the code shown below:
// This code is in another WPF application.
private void OnStylusDown(object sender, StylusDownEventArgs e)
{
// Set a breakpoint here.
}
But the breakpoint never reached until I closed the transparent WPF window which is on top.
I pushed the very simple code to GitHub: dotnet-campus/TouchIssueOnWindows10.0.17134. Cloning it might help a little.
Why does this happen and how to solve it? Any reply is appreciated.
Updated
Microsoft has fixed this issue in .NET Framework August 2018 Preview of Quality Rollup.
August 30, 2018—KB4346783 (OS Build 17134.254)
Addresses an issue where touch and mouse events were handled differently in Windows Presentation Foundation (WPF) applications that have a transparent overlay window.
Original
After a whole week's debugging, I finally find out the solution.
Just add a ResizeMode="NoResize" property for the Window as the code shown below:
<Window x:Class="TheWPFCoveringWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None" WindowState="Maximized"
AllowsTransparency="True" ResizeMode="NoResize"
Background="Transparent" Topmost="True">
<Button Content="Test" Width="200" Height="100" />
</Window>
#lindexi has posted this issue and this solution into his post. If you want more information about this issue, read win10 17025 touch bug - lindexi for more details. (This post is written in multiple languages, so you'll miss nothing even if you ignore the unknown characters.)
Actually, I still can't figure out why this property helps.
Could anyone explain the reason for this issue?

Trying to have multiple content with user control [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Below is the xaml code I have for a custom user control. My goal is to create a control which displays a graphic in the OuterBox, but then will also allow me to load another graphic to be displayed on top of it using the InnerBox section. For example, the first/bottom/Outer graphic could be a picture of a dog. If a user clicks this and answer is correct, a check mark graphic would appear on top of the dog. If a wrong answer, a X would appear. That is a very simplistic example, but illustrates the problem. My program would have many permutations of outer and inner graphic combinations, so it is not feasible to have all possible combinations of outer and inner graphics options in a resource dictionary.
I can see 2 options, with number 1 being preferable.
Create control where you can set the outer and inner viewbox child content individually. Right now, I can do one or the other, but not both. Whichever content is set first is what appears. Is it even possible?
Generate xaml strings on the fly and piece the inner string within the outer string, thus creating a nested xaml string. I have verified I can put a nested xaml string into a control from a resource dictionary and it will work. To do this, how can I set the viewbox child content to a dynamically created xaml string through code, as will not be possible to store in dictionary ahead of time? If this works, I could pull two xaml strings (outer and inner graphic), piece them together, and then display the nested graphic.
I would like to do this in VB, but will work it out in C# if need be.
Any help would be greatly appreciated.
My control definition.
<UserControl x:Class="CardBox"
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"
xmlns:local="clr-namespace:TestingNested"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Viewbox Name="OuterBox">
<Canvas Width="100" Height="100" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- need outer content dynamically set here -->
<Viewbox Name="InnerBox">
<!-- need inner content dynamically set here -->
</Viewbox>
</Canvas>
</Viewbox>
</UserControl>
I would use a Grid to overlay the inner graphic on top of the outer graphic, and control the visibility of the inner graphic. A Viewbox can have only one child element. Grid can have multiple. The child with the higher ZIndex goes on top.
<UserControl x:Class="CardBox"
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"
xmlns:local="clr-namespace:TestingNested"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid Width="100" Height="100">
<Image Source="{Binding Path=OuterGraphic}"
Panel.ZIndex="1"/>
<Image Source="{Binding Path=InnerGraphic}"
Panel.ZIndex="2"
Visibility="{Binding Path=InnerGraphicVisibility}"/>
</Grid>
</UserControl>
In your code-behind, add the OuterGraphic, InnerGraphic, and InnerGraphicVisibility dependency properties like so:
Public Shared ReadOnly OuterGraphicProperty As DependencyProperty =
DependencyProperty.Register("OuterGraphic", GetType(ImageSource), GetType(CardBox), New PropertyMetadata(Nothing))
Public Property OuterGraphic As ImageSource
Get
Return CType(GetValue(OuterGraphicProperty), ImageSource)
End Get
Set(value As ImageSource)
SetValue(OuterGraphicProperty, value)
End Set
End Property
Then you should be able to set the graphics dynamically by setting the OuterGraphic and InnerGraphic properties, and turn the inner graphic on and off by setting InnerGraphicVisibility.

WPF - Make a window re-open when minimized [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I've been trying to make a program, that makes an ellipse move on the screen (by the arrow keys), when I am still able to click the window that is open behind it (for example - Google Chrome) and the ellipse will still be visible and move-able.
I've been trying a lot of things (including TopMost) and nothing worked.
Now, my idea is to make a transparent window, that is un-clickable and will re-open (will be maximized) every time it gets minimized.
Can someone please help me? I have no code that can help, the names of the objects involved don't matter.
I think your questions are already answered elsewhere:
Click-through control in WPF (use <TextBlock IsHitTestVisible="False" .../>)
Preveting the window from minimizing:
a. Cancel minimizing event (intercept the minimize event and cancel it)
b. Preventing from minimizing on "Show Desktop" (Win+D) command (mark the window always-on-top)
I am not sure if I understood your question right, you want to click through the ellipse.
You could for example just use two grids with different ZIndex and just Register when 1 gets clicked. Eg:
<Grid>
<Grid Background="Transparent" Panel.ZIndex="1">
</Grid>
<Grid Panel.ZIndex="0">
<Ellipse Background="Blue" Height="100" Width="200"/>
</Grid>
</Grid>

What is the equivalent way to use Bitmap,Graphics,PictureBox & BitmapCopy() in WPF?

I'll try to explain my problem clearly.
I have a working code in WinForms that has a Board (PictureBox) that shows an image thats generated from a list of users controls (win-forms) by the function UserControl.BitmapCopy() for each user control.
This process begins with a blank image (Graphic type), and for each user control I draw it in a specific location with the function BitmapCopy() of the user control.
The result is an image that looks like a real form (with buttons,labels,etc.), but it’s just an image.
Then I show this image in a picture Box.
Now I need to implement this code in WPF, but I can’t generate an image of each user control with BitmapCopy().
I found this code that does it, so now I can generate a bitmap for each user control, but I don’t know what is the best way to create the Big Board that eventually shows a bitmap that has all the user controls images inside it, in different locations.
I would appreciate any help.
This is the equivalent in WPF:
<Window x:Class="MiscSamples.VisualBrush"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="VisualBrush" Height="300" Width="300" x:Name="Window">
<StackPanel>
<TextBlock Text="Hi, Im a Window!"/>
<TextBox Text="This is a TextBox"/>
<Slider Width="200"/>
</StackPanel>
<Window.ToolTip>
<ToolTip DataContext="{Binding PlacementTarget, RelativeSource={RelativeSource Self}}">
<Grid Height="400" Width="400">
<Grid.Background>
<VisualBrush Visual="{Binding}"/>
</Grid.Background>
</Grid>
</ToolTip>
</Window.ToolTip>
</Window>
The Window's ToolTip consists of a grid painted with VisualBrush whose Visual is the Window itself. It looks like this:
As you can see, Exactly 0 lines of C# code are required to achieve the same in WPF.

How to change maximize button color/texture

Is there any way to change the Minimize button, Maximize button, WPF window frame/border ect. using styles in the xaml?
These buttons are part of the Window Chrome, and therefore are supposed to be left for the user to decide on how they look (Windows has options for changing the color of the chrome). So if you want to take control of the Chrome, it is not as simple as a window style.
You can use the WindowStyle property to get rid of them, or make the window a Dialog-type window, but for more control, you'll need to get into creating custom chrome for your window.
If you want to go down this path, it is definitely possible, but you'll need to look at information about creating a custom chrome for your window. Here are a couple resources, but do your research and see which of these, or what other resources best meet your needs:
Code Project Library
Stack Overflow Answer w/ Links
MSDN Blog
You can remove the default Windows chrome with WindowStyle="None" and ResizeMode="NoResize" and then create whatever borders/buttons you like. E.g.
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None"
ResizeMode="NoResize"
BorderBrush="Blue"
BorderThickness="5">
<StackPanel Orientation="Horizontal"
VerticalAlignment="Top"
HorizontalAlignment="Right"
Height="20" >
<Button Content="Minimize" />
<Button Content="Restore" />
<Button Content="Close" />
</StackPanel>
</Window>

Categories

Resources