Preview of a window (Visualbrush) that is not visible - wpf

I've created a window dynamically that's is in memory but is not visible yet. In other window I want to show a little preview of this window. I'm triying using a visualbrush to achieve this, setting the visual property of the visualbrush.
It works perfectly with a visible window, but if the window is not visible, the visualbrush don't shows anything.
What can I do to show a Preview?

Finally, I did it creating the visualbrush from the main grid of the window instead of the window itself. It works no matter if the window is visible or not, but I'm not sure if it's the right way for doing it.

Related

wpf 4.0 partial button outside of main window

I'm trying to figure out a way to have a selected button/item extend past the main window and 'connect' to the spawned window. I'm thinking that a transparent window behind the 'toolbar' window and the spawned item. Am I on the right track?
Here is what I'm trying to do:
Thanks for the input.
You look like you on the right track. A control cannot extended beyond the bounds of a window so you would have to make the window transparent and color only part of the window to make it look as if the selected item is extended beyond the window bounds.

WPF Popup Alternative

I have a window with a popup that pops when an item in a listview is double clicked.
It centers to the main window and looks really nice floating there.
The problem is when the user moves the main window or selects another program, and the popup floats on top of other stuff.
I would like to have something like a popup, meaning that it floats on top of other elements in the window, but sticks with the main window when it moves (stays centered), and doesn't float on top of other programs.
Can I make a popup act like this, or is there a better way to do it?
Popups will not move while the window is resized or moved. Because, Popups/Context menus are not the part of Visual Tree. You have to use Adorner for this. I will suggest to read this four part series for a quick start on Adorner.
It's possible that an Adorner will fit your needs in this case better than a popup. Adorners can float above your window, too. There are a few differences, mainly that an adorner is bound to a UIElement (which include windows).
If you are willing to use a third-party/open source (MS-PL) option, the Extended WPF Toolkit has a ChildWindow control.
It's technically not a separate window, but it appears to be a separate window to the user.
I have not found a way to make Popups stop doing that in WPF
As an alternative, you can create a UserControl which acts like a Popup.
Usually I host the content section of the app along with the Popup within a Canvas control, and when IsPopupOpen gets changed to True I set the popup Visibility = Visible.

Force WPF to render a window while hidden?

I've noticed that when I make a change to the visual presentation of a window while the window is hidden, the changes are not immediately visible when the window is shown. Rather, the window appears briefly in the state it was in when it was last-visible, taking 0.5-1 seconds to display the updated form.
This can be confusing and ugly as when my window is shown, it defaults to having no items selected, yet if there were items selected when it was closed, it will appear as though those items are selected again when it is opened, only to disappear a second later.
Is there any way I can force WPF to render the window even though it is not visible, so that when it is shown it is in the correct state?
Turns out this is a limitation of the operating system--apparently WPF can't access the window bitmap or something if the window is hidden. I found a workaround by setting the Opacity of the window to 0 or 1 instead of hiding/showing and it seems to work pretty well.

Clip a wpf Popup at bounds of a main window

From what I understand, the popup exists within it's own visual tree. However, I've noticed a few properties, Clip and ClipToBounds. What I am wanting to do is Visually clip a popup at the right and bottom edges of a window regardless of the fact that the popup is independent of the bounds of the window. I'm not using XAML, but if somebody knows how to do it in XAML, then that's fine. I can get to the main window using System.Windows.Application.Current.MainWindow. Is it possible from this to get a value that I can use to clip the popup? I'm assuming that if there is a value that I can use, then I would be able to bind the clipping of the popup to that value. This is really not necessary since after the popup initially opens, if the window gets moved or resized, the popup closes. So I would really only need to clip the popup when it opens. The reason I would like to do this is because although I am using a popup, I don't want it to appear as a popup that exists outside of the window. FYI this is for a popup calendar for a custom datebox. Any ideas, as well as clarification of misconceptions that I may have, would be greatly appreciated.
Furthermore, the popup can be launched from a user control that is not directly on the Main Window. So in that case it would be easier to use a popup. As apposed to a UC inside the XAML
I know this is a year old post, but in case any others come here looking for answers... If you don't need the popup to be outside of your window, why use a popup at all? It'd be far easier to simply use a control in a canvas (for instance) and control it via its Visibility property. Then you'd automagically get your clipping.

Using a XAML vector image as a window icon

LearnWPF.com posted this article about converting bitmap images to XAML and using them in your applications.
The outer element of the XAML image is a Canvas. However, the Window.Icon property only accepts an ImageSource object. Does anyone know how I can 'wrap' the Canvas in an ImageSource so I can use it as a window icon?
Alternatively, is there a better way to use a XAML image as a window icon?
The WPF window Chrome(header bar, Icon etc) are part of the typical Win32 Window system. So it was not built to use with Vector Icon, you need to specify an .Ico, .png or some other supported image file to the Window.Icon property.
But if you really want to make a Vector(XAML) animating Icon, you need to think about the concept of Chrome less window. That means gets rid of the old style window chrome(WIndowStyle="None") and build our own chrome entirely with WPF, then you can place your Vector directly over the left top corner and it will just work as you do with any other XAML Visuals in the application.
Read more about how to create Chromeless window on bellow links
How do I implement a chromeless window with WPF?
Creating a Custom Window in WPF

Resources