How webview2 runs in privacy mode - wpf

I have a WPF application that runs multiple instances at the same time
One control in the application is webview2. I think webview2 between multiple instances runs in a private mode without affecting each other. How can I do this?
Thank you very much for your help.

Related

How to prevent XBAP Browser application from being closed in a web browser

We are developing a WPF application with a XBAP part running in a web browser, both using Caliburn.Micro framework.
There are no problems with implementation and deployment except that there is a requirement the application should not allow user to close it when instantly when some data was modified on the active window and user did not press save.
In the desktop application it is just easy as overriding Caliburn's CanClose method which itself is a part of Window.Closing callback. This callback is executed and CancelEventArgs.Cancel can be set if necessary.
In the XBAP application, Application.Current.MainWindow is a RootBrowserWindow and when it's Closing and Closed events are subscribed, these never get called even if callback is a static method (I'm modifying Caliburn.Micro code here for testing).
My question is how to prevent WPF XBAP browser application running in Internet Explorer from closing when user tries to close the tab or a whole browser window? Application trust is not an issue as we can (and will) ask clients to give full trust for the app.
Sorry to my knowledge, you can't, IExplorer restrictions. You are not even allowed to check if your window is minimized and even certain key combos isn't allowed in XBAP applications. Fulltrust or not, IE issue :(
I thinkered with the same issue as you about 3-4 years ago, + some keybindings, did alot of interop stuff, to no avail from what I can remember.
Cheers
Stian

WPF XAML slow start up for a small application

I'm using VS2010 WPF / XMAL to create a very detailed order form. It has about 50 data items on it all data-bound in xaml. All is fine in development on my win7 PC. When I deploy the app, via one click or an MSI, the application take seconds to download but up to 5 mins to prepare before the login screen is shown on a windows 7 pc. But on my XP machine it's done in seconds, for exactly the same app!. I've trouble shot the order form by commenting out some of the xaml I found that there is breaking point to the amount of items it can show before I get a start up problem. For example I have 30 items without issue but once you add one more then they very slow startup times occur. It doesn't matter which area of the xaml I comment out as soon as it goes to one extra I get the slow start up time?
I'm only using grids, stack panels and textboxes with single items of data. No lists
Very strange as XP doesn't have this problem. Any ideas?
What graphics cards do you have in each machine? It may be to do with there DirectX compatibility? Changing to software rendering might give you an insight (or at least some consistency.
Try the advice from this page:
http://blogs.msdn.com/b/jgoldb/archive/2010/06/22/software-rendering-usage-in-wpf.aspx
This is the profiling tool you should use for WPF:
http://msdn.microsoft.com/en-us/library/aa969767(v=vs.110).aspx
On my windows 7 pc I changed these setting in symantec antivirus; In Auto-protect I disable the Enable File System Auto-Protect option. Also in the global settings I disabled "Insight for" and " Enable bloodhound heuristic virus detection.
After this my app loaded in a second. When I enabled the virus settings back to what it was and did a reboot my app continued load up in seconds.
I'm not sure why Symantec was inconsistent with this issue... By just adding one extra line of xaml, be it a textbox or a label I get a massive difference in behaviour. My assemblies are sign on my build server with domain certificate so I would assume they are trusted.

Getting only gray screen when launching citrix application

Recently we installed a .net WPF application on citrix. When I go and launch it from citrix using RES powerfuse, I only get a grey screen and no controls are rendered on the screen.
The application is open and the main window can be seen but everything is grey in it. The mouse pointer also disappears behind the application.
The funny part is when the people from the operations team launch the application, it works fine. but not for regular users. This makes me suspect it could be something to do with permissions, yet we have given the access to open the program to all users, thats why the icon appears in citrix in the first place
What server are you running the app on? I recall we hit a WPF rendering bug on certain versions of Windows Server (+ XenApp) where the app would only render properly for administrators. This was a .NET bug - nothing to do with Citrix per-say. From what I remember the WPF rendering engine was trying to get access to some system resource that regular users could not access. I believe we only saw this on 2003 servers.
Just did some further digging, I think this is the issue:
http://support.microsoft.com/kb/955692
For quick n temporary resolution:
Check your local machine resolution and Citrix desktop/application resolution.
Equalise the both it will work.
Ex: 1024/762 is the right resolution.
For test: Do maximise n minimize the screen you will see the change.

Is there are any loading speed difference between Page and Window in WPF?

I want to load 10 000 items in a DataGrid in WPF. When using a Window control the data loads faster than when using a Page control. Can someone explain why?
Pages are intended for use in Navigation applications (usually with
Back and Forward buttons, e.g. Internet Explorer). Pages must be
hosted in a NavigationWindow or a Frame
Windows are just normal WPF application Windows [lnk]
This is essentially an XBAP vs ClickOnce problem. Anything in a Page is compiled for and restricted by what WPF is permitted to do in a browser window. This precludes many low level computer operations that WPF Windows can get away with because they are compiled to run from the desktop. Window apps have full access to system resources.
Keep in mind that when you use a Page control, even during debugging, the generated code is build with a browser deployment in mind. All XBAPs are run in a restrictive security sandbox under partial trust. In other words, they are allowed to use certain .NET libraries but banned from accessing others. [ref] Some of these .NET libraries will be responsible for optimizations that therefore can't achieved in a browser deployment.
As such, it makes perfect sense that applications build in Windows would be able to perform most operations faster than apps built in Pages.

How to avoid visual artifacts when hosting WPF user controls within a WinForms MDI app?

When hosting WPF user controls within a WinForms MDI app there is a drawing issue when you have multiple forms that overlap each other that causes very distinct visual artifacts. These artifacts are mostly visible after dragging one child form over another one that also hosts WPF content or by allowing the edges of the child form to be clipped by the main MDI parent when dragging it around. After the drag and drop of the child form is completed the artifacts stay around generally but I've found that setting focus to a different application's window and then refocusing back on to my application window that it is redrawn and all is good again until the child forms are moved once again. Please see the image below which demonstrates the problem.
Those at Microsoft insist that the WinForms MDI is already a sufficient solution for MDI and doesn't need reinventing in WPF although I find it hard to believe they tried creating a WPF app this way because of the obvious shortcomings.
UPDATE: A few extra notes that I left out is that if I create these Forms without setting the MdiParent they are created as regular forms and this issue doesn't happen. This issue seems unique to the WinForms MDI scenario. Also I've currently running on Windows 7 Enterprise and I'm aware the results may be quite different on Windows XP but I haven't been able to test this.
UPDATE: I've found a few other related resources on this issue that I thought I should share.
elementHost repaint problem in MDI
application
elementHost repaint problem in MDI application on Tech Archive
It appears that another workaround is to revert to software rendering as opposed to taking advantage of hardware acceleration. This was the suggestion by Marco Zhou on the MSDN Forums.
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
this.Loaded += delegate
{
var source = PresentationSource.FromVisual(this);
var hwndTarget = source.CompositionTarget as HwndTarget;
if (hwndTarget != null)
{
hwndTarget.RenderMode = RenderMode.SoftwareOnly;
}
};
}
}
I've tested this and this solution seems to work very well and so far is the only solution that I've found for solving this problem within a FoxPro interop scenario which is very similar to the WinForms one I posted about originally. For now I'm planning to use my original Refresh on the MDI Parent solution for my WinForms project but then for my other native interop applications such as when my WPF controls are hosted in Visual FoxPro I'll use this solution. That is unless of course if a more elegant solution is discovered for either of the cases.
Also it's important to note that from what I'm aware software rendering is the only option on XP systems and normally Visual FoxPro nore WinForms normally take advantage of the same type of hardware acceleration that native WPF apps do on Vista OS and up. So using this option may not be as bad as it sounds when you do have to deal with interop. Currently I'm not aware of any related side effects when using this solution but if there are any those would have to be taken into serious consideration.
Well, I may have found a solution although it feels like a bit of a hack. It appears that if you call the Refresh method on the MDI parent whenver a child MDI Form is moved that the noted artifacts go away. Visually things appear a bit jittery when dragging a window but it seems much more acceptable than the example I showed in my original post.
private void Form1_Move(object sender, EventArgs e)
{
this.ParentForm.Refresh();
System.Diagnostics.Debug.WriteLine(string.Format("Form Moved to: ({0},{1})", this.Left, this.Top));
}
I've tried many combinations in the same vein such as refreshing just the child window that was being moved by calling methods such as Update(), Invalidate(), Refresh() and also I've tried these same methods on the MDI parent as well as Dispatcher.Invoke(DispatcherPriority.Render, ...) and InvalidateVisual() on my hosted WPF control but none of those other methods worked accept for calling Refresh() specifically on the MDI parent.
I realize that this probably isn't the optimal solution since I'm forcing the whole main application window to refresh every time a child window moves a few pixels but as for right now it's the only reasonable solution that I found that works. If anybody else has any alternative solutions or any improvements upon this I will gladly accept your answer instead.
Check video drivers and try disabling hardware acceleration. Most artifacts are caused by bad drivers, failing video card, or insufficient time to complete the refresh.
First troubleshooting step: Update video drivers. Obvious, I know.
I had similar issue, checking my video card settings (NVidia Control Panel) showed global setting set very high causing a longer refresh interval which may be aborted if taking too long. Setting my settings back to defaults resolved most of the issue. But I also run hashing programs which use the GPU intensely so this is likely the cause of my remaing artifact issue which is very seldom now and mostly shows its ugly face in Visual Studio.
Another troubleshooting step I ran across is to disable hardware acceleration for WPF, this can be done in 'HKEY_CURRENT_USER/SOFTWARE/Microsoft/Avalon.Graphics', or maybe an application can do it BUT this is only for troubleshooting; never set these within an application because it will disable for ALL WPF applications. I do not have this registry setting nor did I add it so I am not sure of the success with it, but many say this resolved their issue. Also note some applications have this option available, try disabling it if available.
Another troubleshooting step is to make sure the video card is a proper tier level for rendering. Any card that supports DX9 or greater should be sufficient, but other factors are involved (as is my case) so just because it is on the list does not mean it is adequate for your purpose.
Finally, you can use the Visual Profiler (part of Windows SDK), and other tools, to help determine what is going on more precisely with WPF lacking performance in relation to graphics ability.
Rendering Tier level notes and WPF Performance information --> http://msdn.microsoft.com/en-us/library/vstudio/ms742196(v=vs.90).aspx
Hope this helps someone.
--Ryan Strassburg
Your usercontrol or window loaded event ;
this.WindowState = System.Windows.WindowState.Minimized;
this.WindowState = System.Windows.WindowState.Normal;
it may seem bad solution. no need to hit your head against the wall.
A Turkish proverb says: the best code is the code is running :)

Resources