I've been trying to get CefSharp working with WPF (.NET Core) and every time I try it, it always gives me this error:
FileNotFoundException: Could not load file or assembly 'CefSharp.Wpf, Culture=neutral, PublicKeyToken=40c4b6fc221f4138'. The system cannot find the file specified.
The error occurs here:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent(); <-
}
}
and here is the XAML file
<Window x:Class="testwpf.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
Title="MainWindow" Height="550" Width="625">
<Grid>
<cefSharp:ChromiumWebBrowser Grid.Row="0"
Address="https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions" />
</Grid>
</Window>
Related
I'm trying to make an Hierarchical Navigation View with XAML in a UWP project using a almost unnedited copy of the XAML Controls Gallery App code sample.
It doesn't show any error while compiling but when the app starts it crashes returning the following exception on the code behind at InitializeComponent():
Windows.UI.Xaml.Markup.XamlParseException: Cannot found the text for
this error code Cannot find a Resource with the Name/Key
TabViewButtonBackground [Line: 41 Position: 33]
XAML code:
<Page
x:Class="XizSoft.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:XizSoft"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
mc:Ignorable="d"
>
<muxc:NavigationView x:Name="nvSample8">
<muxc:NavigationView.MenuItems>
<muxc:NavigationViewItem Content="Home"
Icon="Home"
Tag="SamplePage1"/>
<muxc:NavigationViewItem Content="Account"
Icon="Contact"
Tag="SamplePage2">
<muxc:NavigationViewItem.MenuItems>
<muxc:NavigationViewItem
Content="Mail"
Icon="Mail"
Tag="SamplePage3"
/>
<muxc:NavigationViewItem
Content="Calendar"
Icon="Calendar"
Tag="SamplePage4"
/>
</muxc:NavigationViewItem.MenuItems>
</muxc:NavigationViewItem>
</muxc:NavigationView.MenuItems>
<Frame x:Name="ContentFrame"/>
</muxc:NavigationView>
Code-behind:
public MainPage()
{
InitializeComponent();
}
I've found the solution for this problem.
I just needed to add the following line on my App.xaml resources:
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
Source: https://vijirajkumar.blogspot.com/2020/08/uwp-navigationview-cannot-find-resource.html
I am trying to implement auto-update feature in my WPF application. So I am testing out a scratch project and following this guide.
This is my MainWindow.xaml:
<Window x:Class="AutoUpdate.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"
mc:Ignorable="d" Loaded="MainWindow_OnLoaded"
Title="MainWindow" Height="350" Width="525">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" TextElement.FontSize="20">
<TextBlock x:Name="CurrentVersion" Text="Loading..."/>
<TextBlock x:Name="NewVersion" />
</StackPanel>
</Window>
Then, my xaml.cs file:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private async void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
{
using (var updateManager = new UpdateManager(#"C:\AutoUpdate\Releases"))
{
CurrentVersion.Text = $"Current version: {updateManager.CurrentlyInstalledVersion()}";
var releaseEntry = await updateManager.UpdateApp();
NewVersion.Text = $"Update Version: {releaseEntry?.Version.ToString() ?? "No update"}";
}
}
}
The only thing I did different is creating the .nupkg as I created it through NugetPackageExplorer. But I got the following error when run:
Update.exe not found, not a Squirrel-installed app?
What is the Update.exe needed? I have it in my localappdata of my app. What could be missing?
You need first release your app with squirrel.exe --releasify and then install the app with Setup.exe or Setup.msi - it will work.
You cannot debug squirrel UpdateManager - but there is one way: you can first install your app released by squirrel on you computer and then copy Update.exe (from %LocalAppData%/YourAppName/) to parent directory of yours binary files in project. (ProjectName/Bin/Debug or ProjectName/Bin/Release).
For more info: https://github.com/Squirrel/Squirrel.Windows
I am trying to change the MainWindow location in a WPF application from the default startup URI: MainWindow.xaml to Views\MainWindow.xaml. where Views is a folder created inside the project folder.
Uri: this.StartupUri = new System.Uri(#"Views\MainWindow.xaml", System.UriKind.Relative);
I changed the uri and then the application breaks with the following error:
An unhandled exception of type 'System.TypeInitializationException'occurred in PresentationFramework.dll
Additional information: The type initializer for 'System.Windows.Application' threw an exception.
I placed breakpoints and try-catch blocks in the Main method,the InitializeComponent method and the MainWindow constructor to no avail.It crashes and i can't catch the exception.
Main:
public static void Main() {
try
{
wpfTest.App app = new wpfTest.App();
app.InitializeComponent();
app.Run();
}catch(Exception ex)
{
Console.WriteLine(ex.InnerException.Message);
}
}
Does the startupUri have to be changed somewhere else too?It has only one reference :the one in the InitializeComponent method.
To move the MainWindow to a Views folder (namespace), you have to follow this steps
Change the class name in MainWindow.xaml
<Window x:Class="WpfApp1.Views.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:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
</Grid>
</Window>
Modify the namespace in MainWindow.xaml.cs
namespace WpfApp1.Views
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}
Modify the App.xaml
<Application x:Class="WpfApp1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp1"
StartupUri="Views/MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
Move MainWindow.xaml to the Views folder
And thats it.
It does not matter which one you do first/last, but you have to do all of them.
I do have a UserControl (works) which I would like to use in a WPF project. When I run the application I get following error
Unable to load DLL 'VCECLB.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"
This is a C++ dll and if I add it under references it goes to the project folder like this:
I also add it in the output folder \bin\x64\Release but without success. What I am doing wrong here? Any feedback would be highly appreciated!
UPDATE:
The XAML for loading the UserControl looks like this:
<Window x:Class="WpfApplication1LL_Neu.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:lowLightGrab="clr-namespace:LowLightGrab;assembly=LowLightGrab"
Title="MainWindow" Height="350" Width="525">
<Grid>
<WindowsFormsHost Height="290" HorizontalAlignment="Left" Margin="16,10,0,0" Name="windowsFormsHost1" VerticalAlignment="Top" Width="475">
<lowLightGrab:UserControl1/>
</WindowsFormsHost>
</Grid>
</Window>
Thanks
Once added as reference it will be copied to output folder.
For design time you have to add in your Window:
xmlns:VCECLB="clr-namespace:VCECLB;assembly=VCECLB"
I'm writing a Windows 8 Store application and within that I've designed my own user control.
Here is the code for my usercontrol (This is a dummy control but the problem exists with this):
<UserControl
x:Class="Windows8StoreTest.TestUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows8StoreTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Width="70"
Height="40">
<StackPanel>
<Button Content="Hello" Foreground="Pink" BorderBrush="Pink"/>
</StackPanel>
</UserControl>
I've dropped the user control onto my page and give it a name:
<Page
x:Class="Windows8StoreTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows8StoreTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<local:TestUserControl Name="testControl"/>
</Grid>
</Page>
However, when I go to the code behind I can't access the control by that name. It doesn't seem to exist! What is weird is that the control doesn't exists within InitializeComponent() method for the MainPage class which will be why it does exist.
What am I missing from my user control?
I'm using Windows 8 Store, XAML, c#.
Thanks in advance
Try to use this:
<local:TestUserControl x:Name="testControl"/>
Should work...
hello i don't know what is wrong but it should work.i have just made a sample example of it..i am putting it here hope you have done the same way.
<Page
x:Class="App12.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App12"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<local:MyUserControl1 x:Name="hellousercontrol" />
</Grid>
in my mainpage.cs.. i have just use it like this..
public MainPage()
{
this.InitializeComponent();
hellousercontrol.Height = 100;
}
one more this..have build your solution ?
I had the same issue in c++ environment. I observed, I didn't had default constructor in my class, as soon as I added the default constructor, I could use the defined UserControl in my project through XAML file. However without default constructor I was able to use it from within c++ code.