I've an UWP app with following structure:
MyAwesomeApp.sln
Common.csproj
Resources.xaml
Main.csproj (startup project)
MainPage.xaml
MainPage.xaml.cs
App.xaml
App.xaml.cs
OtherProjects...
Can I use Resources.xaml in App.xaml or MainPage.xaml and how?
It depends on the project type of Common. If it's a "Class Library (Universal Windows)" or "Windows Runtime Component" project, then you could directly access the resource file like:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Common/Dictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
If it isn't a "Class Library (Universal Windows)" or "Windows Runtime Component" project, then you can't do that.
Related
I am working on migrating Xamarin.forms application to .net maui and I follow steps mentioned in Microsoft site,
change .csproj to Microsoft.NET.Sdk for forms csproj, droid csproj, iOS csproj,replace Xamarin.forms namespace with maui,add mauiprogram.cs,
Delete Xamarin.Forms and Xamarin.Essentials nuget references,
set build action for xcml file to MauiXaml, replace forms xmlns in XAML file with xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
<?xml version="1.0" encoding="UTF-8"?\>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
When trying to build the forms project getting XamlC error XFC0000 : Cannot resolve type "ContentView", XamlC error XFC0000 : Cannot resolve type "ContentPage".
As Steve suggested, you can create a new project with Maui template and then create project file in Maui Project based on your Xamarin Project.
I'm migrating my WinPhone8.1 project to UWP and I found some incompatibility of the behaviors in the xaml. It seems that I need to install Microsoft.Xaml.Behaviors.Uwp.Managed and Microsoft.Xaml.Behaviors.Uwp.Native. However, after installation, I got compilation error like this:An assembly with the same simple name 'Microsoft.Xaml.Interactivity' has already been imported. Try removing one of the references... I think xaml.interactivity is provided by the framework and I cann't see it in the references in solution explorer. I'm wondering if any one can give some idea on this. Here is a screenshot of the references excluding my own dlls.
Code snippet
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior
EventName="ItemClick">
<core:InvokeCommandAction
Command="{Binding ViewSomeCommand}"
InputConverter="{StaticResource ItemClickedToSomeConverter}" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
Only install Microsoft.Xaml.Behaviors.Uwp.Managed will solve the problem
i tried it and worked with me.
Even though I have declared the resource dictionary in App.xaml, I don't get the Key resolved in my xaml pages during design time. It works fine during runtime. Also my BasePage is not resolved.
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Themes/Generic.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Any help will be appreciated. Thanks
Sometimes, the XAML designer just get lost.
If everything is working at runtime, it means that your code is correct. You can try to rebuild you solution to let VS regenerate everything and allow the XAML designer to work again. Sometimes, closing the designer tab and reopening it after a rebuild can help....
In my phone application I've made a user control. Everything works, until I add a ResourceDictionary:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../AppStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
When I add the above xaml I'm still able to build and run the application, and it works as it should with the defined styles, but in Visual Studio the Design view now states:
Design view is unavailable for x64 and ARM target platforms.
Removing the above xaml resolves the problem, but then I cant style the buttons by using a resource dictionary.
Add the ResourceDictionary to the Application.Resources in App.xaml, it will solve the problem.
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../AppStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
OR you can switch the project platform to x86.
Configuration manager => Platform => x86
Extra info about the problem: Design view is unavailable for x64 and ARM target platforms
I want to work with a DataGrid in Kaxaml. How do I reference the toolkit dll?
Copy WPFToolkit.dll to "C:\Program Files\Kaxaml\"
Restart Kaxaml
Now you can use such namespace:
xmlns:dg="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
Another option would be to make a junction and add a probing path to Kaxaml's config.
Make Junction to code
run elevated cmd
cd "c:\Program Files (x86)\Kaxaml"
mklink /J ProbeFolder "c:\path-to-your-code"
Modify Kaxaml.exe.config
run elevated notepad
open "C:\Program Files (x86)\Kaxaml\Kaxaml.exe.config"
add the following to the <configuration>:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="ProbeFolder"/>
</assemblyBinding>
</runtime>
save the file
restart kaxaml
When mapping custom classes and namespaces in XAML using the clr-namespace/assembly notation, you can't specify the path of the assembly containing the class but just the assembly's name (more details can be found on MSDN), since all referenced assemblies must be linked during the XAML compilation via the project file.
Kaxaml doesn't support the concept of a project since it doesn't do any compilation but rather dynamically parses and renders the XAML entered in the editor "on-the-fly" by using the System.Windows.Markup.XamlReader class.
This means that when using Kaxaml you can only reference classes contained in the assemblies that are part of the .NET Framework.
Building on top of Todd White's solution (& this is future reference for myself too) your XAML in Kaxaml would reference a 3rd party library as follows:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:dxlc="clr-namespace:DevExpress.Xpf.LayoutControl;assembly=DevExpress.Xpf.LayoutControl.v13.2"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- Layout Control Start -->
<dxlc:LayoutControl Orientation="Horizontal">
</dxlc:LayoutControl>
<!-- Layout Control End -->
</UserControl>