Using AdControl to display ads in a WPF application packaged for UWP - wpf

I (appear to) have successfully created a UWP package for my WPF application using the following guide:
https://learn.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-packaging-dot-net
Now I would like to take advantage of the AdControl class to display banner ads in my project, as detailed here:
https://learn.microsoft.com/en-us/windows/uwp/monetize/adcontrol-in-xaml-and--net
Is this possible? I don't see the "Universal Windows" section under References for my WPF project, which I can guess is because it’s not an original Universal Windows project. I do see it under References for the UWP package wrapper project I created using the guide above, but that doesn't help me show ads in the WPF project.
Any help appreciated.

You can add Universal Windows reference and use the API in your project as described here but you cannot use AdControl since XAML/UI in WPF is not the same as XAML in UWP and the AdControl is a UWP XAML control:
As mentioned above, there are exceptions to the rule that Windows 10
APIs are accessible from PC software. The first big exception concerns
XAML UI APIs. The XAML framework in UWP is different from the one in
WPF and you really don’t want to be mixing them up, anyways.

Related

Extended DataGrid in Silverlight

How can I add this (ExtendedDataGrid) to my Silverlight project ?
Here is the link to the project I am referring to
http://wpfextendeddatagrid.codeplex.com
Error is:
You can't add a reference to ExtendedGrid.dll as it was not built
against the Silvelright runtime. Silverlight projects will only work
with Silverlight assemblies.
That project was built for WPF and not Silverlight.
This is extended version of WPF toolkit DataGrid control.
Please note: As code of wpf datatgrid in wpftoolkit is moved inside
ExtendedDataGrid project , kindly update Microsoft.Windows.Controls
namespace to ExtendedGrid.Microsoft.Windows.Controls to use existing
objects.
The error message you included in your post states as much.
Silvelright projects will only work with Silvelright assemblies
Remember Silverlight is a stripped down version of .Net used for the browser plugin, and as such will not work with full version of .Net.
Unless you actually go into the source code of that project and try to port it to silverlight then there is currently no other way for you to add that project to your Silverlight project.
I would advise looking into the Silvelright toolkit and it's datagrid. It may not be as full featured as the one you are trying to reference but it covers the basic requirements for a datagrid in silverlight. There are also some open sourced versions that have been extended for silvelright.

how to use ProgressRing in a WPF application for windows

As simple as in the title, I'd like to know how to use a ProgressRing on my gui. I can't figure out how to import the Windows.UI.Xaml.Controls namespace in which seems to be located.
Thanks!
Eugenio
I don't think you can add a reference to a Windows Store Apps DLL to a WPF project, they are built against different versions of the framework.
You could however use a ProgressRing from a different WPF targeting DLL; MahApps Metro has one https://mahapps.com/docs/controls/progressring (source is on github so you can just take what is needed without having to jump fully into the metro style)
Or you could implement your own following a tutorial http://henryzhu1997.wordpress.com/2013/06/18/creating-a-progressring-for-wpf/

WinRT and WPF in Windows 8

As I understand, WinRT is a different version of WPF written without using the underlying Win32 APIs.
What's the relation of WinRT and WPF? Will WPF work under Metro in Windows 7 or will it launch the classic desktop?
That's not so clear from the Keynote. If someone has Windows 8 installed can confirm it's behaviour.
Thanks
WinRT is a replacement for the Winapi. The api is native, very unlike WPF that runs as a layer on top of the CLR. It certainly resembles WPF, part of what causes confusion. It adopted the metadata format of managed code, replacing type libraries of old. And uses XAML for UI designs, much like WPF, Silverlight and Windows Phone. You can still write WPF apps for Windows 8 but your app can't be published through the store, won't integrate with the Metro desktop nor will it run on tablets that are based on the ARM core. Whether that's a real problem depends a great deal on how well Metro will do in the market place.
There is no relation between WPF and WinRT, just like there is no relation between Silverlight and WPF. Now we have three technologies, WPF, Silverlight and WinRT.
If you try to execute WPF application, it will not execute on Metro, it will execute in the classical desktop only.
In Visual Studio 2011, you have WPF and Metro as two different types of applications, and Xaml for WPF and WinRT is not same, Xaml for WinRT is pretty much same as that of Silverlight as lot of classes which exist for WPF are missing in WinRT library. But most of classes that exist for Silverlight are available in WinRT.
Windows Runtime (WinRT) is an alternative API used to create Metro Applications
(and later server application).
The APIs are class/method/struct based and surfaced to .Net metro apps, html5/css3/javascript apps and C/C++ metro applications.
The implementation is native.
APIs are made visible via .winmd files, which contain metadata very similar to the metadata you have in .Net assemblies.
The APIs are designed to secure and async friendly with many APIs requiring the use of async/await due to them potentially taking more than 50msec to execute.
It includes a subset of Win32 APIs and COM apis.
Anyway... the followings links help... channel9 also has some //Build/ videos on the subject..
Metro style app development
- http://msdn.microsoft.com/en-us/windows/apps/
Win32 and COM for Metro style apps
- http://msdn.microsoft.com/en-us/library/windows/apps/br205757(v=VS.85).aspx
APIs for Metro style apps
- http://msdn.microsoft.com/en-us/library/windows/apps/br211369(v=VS.85).aspx
WinRT is a new library that you can use XAML, but not WPF.
WPF is primarily uses DirectX for visual.
You can use WinRT with:
XAML
C#
C++
VB.NET
HTML/JS/CSS
WinRT is a non managed API based on COM interfaces. You use it by calling objects buit in .winmd metadata files ( Windows\System32\WinMedataData directory).
All the namespaces begin with "Windows.".
You can write your Windows 8 application by using XAML files, but that's the only common point with WPF.

Errors when referencing Silverlight class library from WPF application

I have a WPF application and a Silverlight application. They are both used to display a map and share some of the same functionality.
I have created a Silverlight class library project in order to stay DRY. I'm referencing this from both Silverlight and WPF. It contains some utility methods that are useful in both projects. For example, I have this method:
public static void CenterText(TextBlock name, Polygon poly)
The silverlight project has no problem with this. However, I get the following error when calling this from my WPF application:
The type 'System.Windows.Shapes.Polygon' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'
However, I have this line at the top of the file:
using System.Windows.Shapes;
so WPF can see the Polygon class perfectly fine.
My guess is that the silverlight class library uses a version of the framework which is not compatible with the version that the WPF project is using.
So the question is, am I stuck rewriting exactly the same code in my WPF application or is there some way I can share between the two?
Thanks!
You are right, Silverlight uses a completely separate version of the framework. It's much, much smaller than event the .NET client runtime.
This means you can't mix WPF and Silverlight assemblies in the same application.
I ran into this error because I had downloaded the Expression Blend SDK for Silverlight instead of what I SHOULD have downloaded: Microsoft Expression Blend Software Development Kit (SDK) for .NET 4. It can be found on MSFT's website, here:
http://www.microsoft.com/en-us/download/details.aspx?id=10801
As soon as I downloaded the Expression Blend SDK for .Net, removed all of the Blend SDK for Silverlight references, and added those same references as Blend for .Net, I was up and running.
In Silverlight the class is in System.Windows.dll while in WPF it is in PresentationFramework.dll the library tries to get a hold of the Silverlight assembly which is not referenced by default in a WPF application.

Exception when add Silverlight dll in WPF application

When i added the silverlight dll in the wpf application , i got the following exception.
Could not load file or assembly "System.Core, Version=2.0.5.0". The located assembly's manifest definition does not match the
assembly reference.
This is happening only in VS 2010 professional Beta 2.
You cannot use Silverlight directly in a WPF application, as they do not use the same version of the .NET Framework, thus the error message
Could you give some more details on your scenario ?
If you have a WPF app, you have more than what Silverlight can give to you.
If you are building a solution with multiple products, and one is WPF for the desktop, one is Silverlight for the Web, you need to create 2 different projects in VS.
Take a look at the source tree here:
http://expressionblend.codeplex.com/
Specifically, the Expression.Samples.Interactivity.Design branch.
This shows a few examples of how to put in property editors for use with Blend. I'm not sure if the same concept is transportable to the Cider design surface, but heck, Blend is nicer for pure XAML editing anyways. :)

Resources