What is Windows Presentation Foundation Host? - wpf

I have a .exe of a WPF program which is crashing on a PC that is not the one where the .exe was developed, but it does have a copy of Visual Studio installed on it anyway.
When it crashes and I choose to debug it it invokes the local copy of Visual Studio which informs me that the crash happened at a particular line in "mainwindow.xaml" (N.B. not "MainWindow.xaml"). If I right-click in Windows Explorer on the MainWindow.xaml file (because I don't see the lowercase one) the only "open with" option it gives me is something called Windows Presentation Foundation Host (not, for some reason Visual Studio).
If I take that option it brings up my default Firefox browser which asks what I want to do with it, defaulting to opening it in Firefox, which gives me another Firefox browser which asks what I want to do with it, which gives me another Firefox browser, etc, forever.
So what is the Windows Presentation Foundation Host ? And also is there any significance to the fact that the error referred to "mainwindow.xaml" and not "MainWindow.xaml", the latter being a file I actually have in my project?
This is the MainWindow.xaml file . . .
<Window x:Class="MyAB4D_3DLines.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cameras="clr-namespace:Ab3d.Cameras;assembly=Ab3d.PowerToys"
xmlns:ab3d="clr-namespace:Ab3d.Controls;assembly=Ab3d.PowerToys"
xmlns:visuals="clr-namespace:Ab3d.Visuals;assembly=Ab3d.PowerToys"
xmlns:dxControls="clr-namespace:Ab3d.DirectX.Controls;assembly=Ab3d.DXEngine.Wpf"
xmlns:dxModels="clr-namespace:Ab3d.DirectX.Models;assembly=Ab3d.DXEngine.Wpf"
Title="MainWindow" Height="350" Width="525">
<Grid Background="Black">
<Border Name="ViewportBorder" Grid.Column="0" Background="Black" >
<dxControls:DXViewportView Name="MainViewportView" PresentationType="DirectXImage">
<Viewport3D Name="MainViewport">
</Viewport3D>
</dxControls:DXViewportView>
</Border>
</Grid>
</Window>

Related

WPF Chrome window remove gap between windows

I am building a WPF library that connects windows.
In the example the windows have the following properties:
<Window ...
Height="150"
Width="200"
WindowStyle="None"
ResizeMode="CanResize"
Background="#222222"
AllowsTransparency="False">
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="1"
CornerRadius="0"/>
</WindowChrome.WindowChrome>
I use Chrome window because I need to remove the title and be able to resize.
Everything is working well except there are noticeable gaps between windows, although I want to connect them exactly next to each other.
Example layout with 2x magnifier:
https://prnt.sc/26if2vs
What does it cause, can I handle it inside the app, or it caused by the Windows system?

Is there a way to update the WPF WebView's Microsoft Edge Browser version?

I currently have Visual Studio 2019 and created a WPF app. I installed Microsoft's WebView (an updated web browser) through the Nuget Manager. I ran the app and sure enough it worked flawlessly but after checking the browser's version, it was using the old Edge 18.
My code's extremely simple as I was just testing out the browser, I just added the browser inside the Main Grid and did nothing else:
<Window x:Class="WebViewTrial3.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:WebViewTrial3"
xmlns:controls="clr-namespace:Microsoft.Toolkit.Wpf.UI.Controls;assembly=Microsoft.Toolkit.Wpf.UI.Controls.WebView"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<controls:WebView Source="https://html5test.com/"/>
</Grid>
</Window>
What I tried:
I tried installing the latest version of Microsoft Edge (v81) and rebuild the app. Unfortunately it still runs the old Edge 18 instead of the Edge 81.
What I wanted to happen:
I was expecting it to run the Microsoft Edge 81 as I was under the impression that it would simply use the latest Microsoft Edge.
Is there a way to change the version of Microsoft Edge that the WebView is using?
Unfortunately no. You will have to wait until Microsoft updates to the Chromium version of Edge - which they are planning to do this year I believe.

How do you fix schema / namespace error in Visual Studio 2010? (WPF / XAML)

I'm not sure why, but lately Visual Studio cannot seem to find the schema used in XAML on the root Window.
This is the error message I'm getting:
Message 1 Could not find schema information for the element 'http://schemas.microsoft.com/winfx/2006/xaml/presentation:Window'.
The error results in IntelliSense not working. However, the project still compiles and runs as expected. The problem is the same in every project I open. Starting on a new project gives me the following XAML:
<Window x:Class="WpfApplication2.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>
</Grid>
</Window>
But I'm getting the same error.
I've tried, without luck, all of the following:
Reinstalling Visual Studio 2010
Reinstalling .NET
Removing the Visual Studio directory (\Users\[User]\Documents\Visual Studio 2010).
What do I do to fix it?
This was happening for me because I had configured Visual Studio to open XAML files in the XML (Text) Editor.
To fix the problem, right click on a XAML file in the Solution Explorer, chose "Open With", select "Automatic Editor Selector" and click "Set as Default".
If you want to open XAML documents in full XAML view, go to Tools -> Options -> Text Editor -> XAML -> Miscellaneous and check "Always open documents in full XAML view".
What is the TargetFramework version, is it ".Net Framework 4" or ".Net Framework 4 Client Profile". If it is Client Profile, change it to ".Net Framework 4", you may have one more luck.
You can also get this error if you opened an xaml file that is not included in the project, as it opens by default in the text editor. Then added it to the project.
I fixed by closing the project and re-opening.

Using ATL ActiveX control inside WPF Window application

The COM object was not created. The following is XAML code:
Title="Window1" Height="373" Width="701" Loaded="Window_Loaded">
Draw Contour
<Window.Resources>
<!--<BitmapImage x:Key="MyImageSource" UriSource="c:/cs3/TextActiveX/TestActiveX/Image.bmp"/>-->
<Image x:Key="MyImageSource" Source="C:\CS3\TestActiveX\TestActiveX\Image.bmp"/>
</Window.Resources>
On load event I check:
if (!this.imageView.Created)
and it appears that control was not created (this.ocx is null).
I understand that something wrong with registration. I tried re-register - does not work. I tried run as admin and even disable UAC and restart Vista - does not work. But if I run MFC test application or HTML script it works just fine.
Sorry text was too long and it was cut. I am using WindowsFormHost to host ATL based ActiveX control. I defined both inside XAML code.

WPF transparent borders causes the UI to stop redrawing

As a follow up to my previous question, I am wondering how to use transparent windows correctly. If I have set my window to use transparency, the UI will occasionally appear to stop responding. What is actually happening is that the UI simply is not updating as it should. Animations do not occur, pages do not appear to navigate; however, if you watch the debugger clicking on buttons, links, etc.. do actually work. Minimizing and restoring the window "catches up" the UI again and the user can continue working until the behavior comes back.
If I remove the transparent borders, the behavior does not occur. Am I doing something wrong or is there some other setting, code, etc... that I need to implement to work with transparent borders properly?
Here is my window declaration for the code that fails.
<Window x:Class="MyProject.MainContainer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPF APplication" Height="600" Width="800"
xmlns:egc="ControlLibrary" Background="{x:Null}"
BorderThickness="0"
AllowsTransparency="True"
MinHeight="300" MinWidth="400" WindowStyle="None" >
And the code that does not exhibit the behavior
<Window x:Class="MyProject.MainContainer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPF Application" Height="600" Width="800"
xmlns:egc="ControlLibrary" Background="{x:Null}"
BorderThickness="0"
AllowsTransparency="False"
MinHeight="300" MinWidth="400" WindowStyle="None" >
Are you using .NET 3.0, or .NET 3.5 on Windows XP SP2? If so, this is a known problem with the transparent window API that has been fixed in .NET 3.5 and SP3 of XP (and I think SP1 of Vista). Basically when you set the AllowsTransparency to True, the WPF pipeline has to render in software only mode. This will cause a significant degradation in performance on most systems.
Unfortunately, the only thing you can do to fix this is to upgrade to .NET 3.0 SP1 (included in .NET 3.5), and install the appropriate service pack for Windows. Note that the transparent windows are still slower, but not nearly as bad. You can find a more in-depth discussion here.
I think that I've finally found a workaround. From everything I've read this problem should not be occurring with XP SP3 & .NET 3.5 SP1, but it is.
The example from this blog post shows how to use the Win32 API functions to create an irregular shaped window, which is what I"m doing. After reworking my main window to use these techniques, things seem to be working as expected and the behavior has not returned.
It is also of note that the reason the author recommends this method is due to performance issues with WPF and transparent windows. While I believe it may be better in .NET 3.5 SP1 that it was, this was not that hard to implement and should perform better.
I am running on Windows XP Pro SP3 and using .NET 3.5 SP1. I have also verified that the project is targeting version 3.5 of the framework.

Resources