Compiling content without XNA - c#

I have a Content Project for an XNA game, but I'm embedding the game inside a WinForm so I'm not actually using the Microsoft.XNA.Framework.Game class.
How can I make the Content project build with the WinForm's project? I tried adding it as a reference, but the Project isn't listed to be added.
To make it clear, I have two projects in my solution:
KinectGraphics
XNARenderContent
How can I make XNARenderContent build along with my KinectGraphics' project?

As you are using a WinForms application, can I draw your attention to this article.
You can change the Build Order if this is causing you a problem.
If you are struggling to get the Content project in your WinForms application as a reference, then I would definitely take a look at the link above.

Related

Migrate Xamarin Forms Effect to .NET MAUI

For a Xamarin Forms application, I have been using a solution to track touch using code from an example out of Microsoft's Xamarin Forms Sample Project, specifically the Touch Tracking Effect sample.
I took that sample and simplified it down to just directly starting up with the BoxViewDraggingPage.xaml from App.xaml.cs and removing all other XAML files. That compiled and ran fine.
I then created a .NET Maui App with the same BoxViewDraggingPage (and the same TouchActionEventArgs.cs, TouchActionEventHandler.cs, TouchActionType.cs, and TouchEffect.cs) as was in the Xamarin Forms version.
I added the same TouchEffect.cs files that were in the sample for the specific platforms (iOS also has a TouchRecognizer.cs file)
When running it at that point I got the following:
So then I tried following the instructions for Migrating Xamarin.Forms Effects. The explanation for how Xamarin.Forms effects were set up matched perfectly, but it was unclear to me from that page what class the section titled "Effects in .NET MAUI" was replacing since it had a different class name than the previous code snippets earlier in the article. It seemed like it is replacing the FocusEvent class in the shared platform code and then specifies the platform specific code within #if platform sections (#if WINDOWS, #if __ ANDROID __, etc.) and so I am guessing that means the TouchEffect.cs files are no longer needed in the platform specific folders.
I didn't have a chance to find out if that was the case or if it works, because when I try to compile, I get:
I don't find any missing Nuget packages or assemblies when I tried searching. If I click the dot after Platform, I get the following choices, with instructions to use the navigation bar to switch contexts:
But I am already targeting net6.0-windows10.0.19041.0:
so I'm not sure why it says Not Available for that.
So, I am stuck trying to get this to work.
I am looking either for a solution to get the sample code working as it is in the Xamarin.Forms project, but for .NET MAUI (whether that be set up how the sample originally had it or how it is described in the Migrating Xamarin.Forms Effects link) - it could be that I am missing something simple in how to get that Microsoft.Maui.Controls.Compatibility.Platform.UWP piece to compile.
Or, the other possibility is that same link says that .NET MAUI Handlers can also handle this type of scenario. So if someone can show all the pieces that would need to be modified in order to do the same solution but using .NET MAUI Handlers, I am open to that. But it seems that the easiest path, though, should be to get the Effects working in .NET MAUI since everything is already written that way. I am just leaving both options open in looking for a solution.
EDIT:
OK, I figured out why the UWP portion had red squiggles under it. I figured out what "using the navigation bar to switch contexts" in the above screenshot meant. It meant I needed to select the context in the dropdown pictured below:
However, this just moves the squiggles to PlatformEffect and I cannot figure out what to do with the context or anything else to resolve that:
OK, I found out that PlatformEffect now inherits from Microsoft.Maui.Controls.PlatformEffect instead of the separate Platform inheritances shown in the Migrating Xamarin.Forms Effects example. That example is out of date and I didn't realize that and so it was confusing me.

Visual Studio: What's the correct way to reference resources across projects?

An .xaml image location in a secondary reference is not becoming the correct resource location during runtime, it refers to the primary reference resources folder instead. How can I change this?
Background -
I have a solution with several projects. The important three projects here are
a WPF project which builds as a class library
a default class
library
a console app for testing
The WPF project has a .png image in its resources. In the MainWindow created it's called via:
<ImageBrush
ImageSource="pack://siteoforigin:,,,/Resources/MyDemoImage.png"
Stretch="Uniform"/>
When I run an instance of the WPF window directly through the console app, it works fine. The resource reference becomes during runtime:
C:\Users\me.me\Documents\Visual Studio 2015\Projects\sol\
WPFProjectName\
bin\Resources\MyDemoImage.png
But if I create a reference to the WPF project within the class library project then call an instance of the class library, the address becomes
C:\Users\me.me\Documents\Visual Studio 2015\Projects\sol\
ClassLibraryName\
bin\Resources\MyDemoImage.png
So this "pack" address becomes a reference to the class library resources rather than the WPF project resources folder.
Now, I think I could simply add the resource to that middle-man class library too, but I'm wondering if there's some correct way to reference a "secondary" resource, so I only have to add images once?
By the way, the error I get when I try to compile this is System.Windows.Baml2006.TypeConverterMarkup - I've found answers regarding this but tried what they say to no avail (mark image as copy always etc.)
Change
pack://siteoforigin:,,,/Resources/MyDemoImage.png
to
pack://application:,,,/AssemblyName;component/Resources/MyDemoImage.png
Thanks to #Clemens for his advice. This worked great.
I just wanted to answer and share a bit of other frustration-gathered knowledge I found while experimenting with this.
Using pack://application:,,,/AssemblyName;component/Resources/MyDemoImage.png worked great for me for my first image. I then had loads of trouble trying to do the same thing for a 2nd/ 3rd image. It kept compiling ok but on runtime the inner exceptions were throwing out that it couldn't find "resources/mydemoimage.png"
The reason for this was due to the BuildAction on the images. I'd been playing with the different types, some of which worked for my local copy (e.g. setting BuildAction to Embedded Resource actually fixed the initial issue I was having) BUT for the pack://app... to work, compile and then carry through to install and be instanced in another application (e.g. VBA in Excel)...
The BuildAction MUST be Resource
I was extremely lucky that I'd set this by chance before trying Clemens' answer because if I hadn't I would have assumed it just didn't work! But it does!

C# WPF Library creating

I have a WPF project. I want to use this project in other new projects using a .DLL file, Like MessageBox form in C#, when we use MessageBox.Show to create a form.
Library project file cannot specify ApplicationDefinition element.
When i change the output of the project to "Class Library", the "InitializeComponent();" method makes an error, so does many other methods in the constructor of my window, saying
The name 'InitializeComponent' does not exist in the current context
How do i solve this? and how do i use my library once created?
You can't simply port it to a Class Library. You can hack at the app.xaml and so forth, but it would be best if you create a new "WPF User Control Library" or "WPF Custom Control Library". Migrate over your existing code to it. Make sure to expose Public classes and methods that you wish to call from outside of the library.
You can create a Solution to contain your new library as well as a test WPF Application. That way you can add a reference in the application pointing to your library project. Testing would be easier that way.
As far as how to use the library -- you'll need to do some research on that. There are a number of ways to go about it depending on your needs.
OK, the problem is that you project is an app, not a library. Just changing it to library in settings wont help.
The best this to do is to create a new project of type 'user control library', and then copy all of your xaml and classes over to the new project
Deleting App.xaml from my project worked.

How to share code and resources between projects

I have two projects named Project 1 and Project 2. I am porting my application from iOS to WP8 and I have ported my iOS_Project 1 to WP8_Project 1. In iOS I have the flexibility to add the files as references and thereby I can achieve code reuse. I would like to perform the same process in WP8, but I couldn't find proper help and here's the question. (Here I want to refer all the classes, images and xaml files like MainPage.xaml)
I know pretty sure about one thing that wpf/forms/.NET projects differ with WP8 structure. Please do provide some help.
Thanks.
When you have add your item to one project, select the option to Add Existing Item to the other project. Navigate to the item you want to add and then you should find a drop-down arrow on the appropriate button to allow you to add the item as a link. That means that there will only ever be one copy of that item but it will be used in both projects.That said, if possible, I would suggest that you break the common functionality out into a library project that you then reference in both the other projects. If you create a portable library then you could use it in a Windows 8 app as well.
You can use references in Visual Studio 2012 - there is no problem. However, PCL (Portable Class Library) is a better solution. Here is example how to add files as link in Visual Studio 2012.

Expression blend convert example from Silverlight into WPF

Hey! I was looking at a cool layout example in particular the V3FluidLayout.xaml found inside this set of examples : http://gallery.expression.microsoft.com/en-us/DynamicLayoutTrans
Anyhow - this appears to be a silverlight app - it runs within a browser. I am trying to pull the V3FluidLayout example into a WPF app - and struggling.
I "add an existing item" pulling the .xaml file into my project. When it goes to compile it, the following errors are found :
Are these artifacts Silverlight? The following is the xaml code within the V3FluidLayout.xaml file
http://pastebin.com/h9ujUax6
Can anybody help me pin why this is not working - and how I can convert that xaml code to work inside my wpf app.
Thanks
Andy
Basically (and from only a quick glance), you'll need a reference to the WPF versions of System.Windows.Interactivity and Microsoft.Expression.Interactions - they are part of Blend. Actually look at the references of that project and find the exact same references, only for WPF.
It looks like they contain pretty much the same classes for both WPF and Silverlight, so I think it should work in the end.
Add references to the interactivity assemblies found here:
C:\Program Files (x86)\Microsoft SDKs\Expression\Blend.NETFramework\v4.0\Libraries
You need to install the Blend SDK to get them, the come with Blend also.

Categories