I have a XAML Page which inherits from a userdefined class of mine:
<xpap:GenericListPage
x:Class="my.View.ListPage"
xmlns:xpap="clr-namespace:my.View.Generic" ... />
Initially I wanted to use a generic base class for my XAML page, but that was no possible (at least in WP7; is it possible in WP8 to use generic base classes for pages?). So I ended up with this work-around (ExtendedPhoneApplicationPage inherits from PhoneApplicationPage adds extra functionality/behaviour that all my pages like ListPage etc. should have in commen):
namespace my.View
{
namespace Generic
{
public partial class GenericListPage :
ExtendedPhoneApplicationPage<ListViewModel>
{
...
}
}
public partial class ListPage : Generic.GenericListPage
{
...
}
public class ExtendedPhoneApplicationPage<T> :
PhoneApplicationPage where T : class, IViewModelBase
{
...
}
}
This worked fine all together until I installed the WP8 SDK (as far as I can remember). The designer says "invalid markup" and there is an error saying: "The name "GenericListPage" does not exist in the namespace "clr-namespace:my.View.Generic"."
The strange part is, that the solution compiles and can be deployed on the emulator. Anyone know why or how to eliminate the error?
Related
When Excel tries to call a method in a abstract base class i get a Run-Time error
"Cannot run Marco 'MarcoName'. The macro may not be available"
I can run code from the super class.
The code is similar to this
public abstract class MyBaseClass
{
public static bool MyMethod(string path)
{
if(Valid(path))
{return true;}
return false;
}
}
This code is in a separate assembly imported via a nuget package
The calling code is similar to the below
public class MyClass : MyBaseClass
{
public static bool MyOtherMethod()
{
return true;
}
}
Marking the methods with the "[ExcelFunction]" attribute has no effect.
I am loading the xll file like so,
Application.RegisterXLL (path)
I call the method like so,
Application.Run("MyMethod", path)
Only code in assemblies that are included in the <ExternalLibrary ... /> list in the .dna file are scanned for functions to register. Maybe your external assembly is not mentioned there.
Also, abstract types were not always considered. It looks like this changed at some point, if I look at the code that scans the assemblies here: https://github.com/Excel-DNA/ExcelDna/blob/57c2d0a499a044f6cd1c4ae2c9fbf5b084159dea/Source/ExcelDna.Integration/AssemblyLoader.cs#L93
So it might depend on your Excel-DNA version too.
Easiest might be to have a class with all the functions you want to export, where you can add the Excel-specific attributes (<ExcelFunction .../>) and just forward the calls internally.
I am trying to create and use a DLL in Xamarin.Forms Project. This is given in the Charles Petzold's book 'Creating Mobile Apps using Xamarin.Form'.
It gives the following method to access the library that I have created
"From the PCL project of your application solution, add a reference to the library PCL assembly which is the dynamic-link library generated from the library project"
My library project is this
FILE: HslColorExtension.cs
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Xamarin.FormsBook.Toolkit
{
public static class Toolkit
{
public static void Init()
{
}
}
public class HslColorExtension : IMarkupExtension
{
public HslColorExtension()
{
}
public double H { set; get; }
public double S { set; get; }
public double L { set; get; }
public double A { set; get; }
public object ProvideValue(IServiceProvider servicePRovider)
{
return Color.FromHsla(H, S, L, A);
}
}
}
THE actual project is CustomExtensionDemo
In that the MainPage.xaml is
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:toolkit="clr-namespace:Xamarin.FormsBook.Toolkit;assemby=Xamarin.FormsBook.Toolkit"
x:Class="CustomExtensionDemo.MainPage">
<StackLayout>
<Label Text="UTKARSH">
<Label.BackgroundColor>
<toolkit:HslColorExtension H="0" S="1" L="0.5"/>
</Label.BackgroundColor>
</Label>
</StackLayout>
</ContentPage>
THE METHOD HOW I ADDED THE DLL TO THE APPLICATION
FROM THE LIBRARY IS TOOK THE PATH THAT GENERATED THE DLL
C:\Users\admin\Desktop\Xamarin.FormsBook.Toolkit\Xamarin.FormsBook.Toolkit\obj\Debug
The name of the DLL is
Xamarin.FormsBook.Toolkit.dll
I added the reference to the actual project. browsed the path to
C:\Users\admin\Desktop\Xamarin.FormsBook.Toolkit\Xamarin.FormsBook.Toolkit\obj\Debug
and added the DLL : Xamarin.FormsBook.Toolkit.dll
Everything compiled correctly But I am getting a complete white screen on the Android Phone I am having .
POINTS:
1. I have set MainPage.xaml as the MainPage in the App.xaml.cs.. I have tried to put Label without the property element syntax and that worked.
I have not checked on iOS I think that there it would have the same problem as the problem could be in method of using the DLL in the application.
IDE:VS 2017
THE ERROR THAT IS DISCUSSED IN THE BELOW DISCUSSION
NOW I REQUIRE SOME WAY TO REMOVE THE "Windows Phone Silverlight 8.1" AND IT DOES NOT GIVE OPTION TO REMOVE THAT.
I'm fairly certain your problem is incompatible targets of your PCL.
Instead of adding the reference by browsing for the DLL, add it by selecting the project. This approach will check for compatibility of the DLL. Most likely you will need to change targets, fool around with nuget, etc.
Secondly I would recommend that your first platform for testing be UWP. There seems to be much better diagnostics on UWP. When I tried your code, I got the white screen on Android, but when using UWP as a platform I got an exception that said the HslColorExtension could not be found in the DLL.
If you follow these steps it should work for you:
You mis-spelled assembly as "assemby" in your XAML.
xmlns:toolkit="clr-namespace:Xamarin.FormsBook.Toolkit;assemby=Xamarin.FormsBook.Toolkit"
To make sure we're starting clean, let's just create a fresh Xamarin.FormsBook.Toolkit project and get rid of the one you've been using:
a) Copy out the code that you've already written so you don't lose it.
b) Create a new Xamarin.FormsBook.Toolkit project and only target those platforms that you would feasibly use this toolkit in. For example you would never use this in Silverlight because you're going to be referencing IMarkupExtension which is specific to Xamarin Forms.
c) Add a reference to your Toolkit project from your Xamarin Forms PCL project (looks like you're calling that "CustomExtensionDemo"). Don't reference the .dll but rather the project itself. This will spare you other headaches down the road.
d) Copy your HslColorExtension file (and any other classes you have) back in to the new project.
e) Add the Xamarin.Forms Nuget package to your Xamarin.FormsBook.Toolkit PCL, and a "using Xamarin.Forms" line at the top of your HslColorExtension file so that it recognizes the IMarkupExtension interface.
Add an empty Init function (or call it whatever you want) to your HslColorExtension class and then call it from your App.xaml.cs. This has the effect of "waking the compiler/linker up" to the fact that you have an assembly reference in XAML, since XAML is loaded at runtime. It does seem a bit hokey to have to do this, but you can tuck away that ugliness in your App.xaml.cs and you never have to see it again. If you're curious and want to see what's going on, try running it both with and without the call to Init, and take a look at your Android project's bin/Debug folder. When you call Init you'll see your Xamarin.FormsBook.Toolkit.dll appear in that folder. When you don't call Init it doesn't pull your assembly in. That's the core issue here.
Your resulting markup extension code would look like this:
public class HslColorExtension : IMarkupExtension
{
public static void Init()
{
}
public double H { set; get; }
public double S { set; get; }
public double L { set; get; }
public double A { set; get; }
public object ProvideValue(IServiceProvider serviceProvider)
{
return Color.FromHsla(H, S, L, A);
}
}
And your App.xaml.cs like this:
public partial class App : Application
{
public App()
{
HslColorExtension.Init();
InitializeComponent();
MainPage = new MainPage();
}
...
}
If that doesn't solve it for you, let me know! :-)
I'm one of the many windows app developers. I'm sure someone other ran in this problem too. I want to have a base page (c#) where I add methods and use it in some pages without coding it over and over.
I've tried it like this:
Basicpage.cs:
public class BasicPage : Page
{
public void Test() {
}
}
SettingsPage.xaml.cs:
public sealed partial class SettingsPage : BasicPage{
public SettingsPage () {
InitializeComponent();
}
}
On the bold "BasicPage" there are the errors:
Base class of "...SettingsPage" differs from declared in other parts
and
Base type 'BasicPage' is already specified in other parts
Does someone know a solution?
I assume SettingsPage has a XAML part, which also needs to be derived from BasicPage:
<local:BasicPage x:Class="MyNamespace.SettingsPage" ...>
<!-- settings page content -->
</local:BasicPage>
When I try to open a new viewmodel I'm receiving the following error:
Failed to load ViewModel for type EasyBudget.Core.ViewModels.GridCategoryViewModel from locator MvxDefaultViewModelLocator
It´s also shows:
No symbols found.
And shows that cannot find or open the PDB file.
My viewmodel:
public class HomeViewModel
: MvxViewModel
{
private Cirrious.MvvmCross.ViewModels.MvxCommand _listCommandCategory;
public System.Windows.Input.ICommand ListCommandCategory
{
get
{
_listCommandCategory = _listCommandCategory ?? new Cirrious.MvvmCross.ViewModels.MvxCommand(DoListCategory);
return _listCommandCategory;
}
}
private void DoListCategory()
{
ShowViewModel<GridCategoryViewModel>();
}
}
And my other viewmodel:
public partial class GridCategoryView : MvxPhonePage
{
public GridCategoryView()
{
InitializeComponent();
}
}
Does anyone knows what may I be forgeting?
Best regards
Wilton Ruffato Wonrath
I believe the problem will most likely be somewhere in the construction of the ViewModel:
perhaps the constructor itself isn't public?
perhaps one or more of the parameters for the constructor couldn't be found?
perhaps some code inside the constructor has thrown an exception
Where you posted 'my other viewmodel' you actually posted code only for your other view. Can you post the code for the ViewModel that accompanies that view?
If you enable your debugger to break on all Exceptions, then this will possibly help you to find the problem that occurs during loading (inside https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross/ViewModels/MvxDefaultViewModelLocator.cs).
If you want to a pdb for debugger symbols, then these can be found inside the folders of http://github.com/slodge/MvvmCross-Binaries - inside the VS2012/Release folders. We are also currently trying to work out how to distribute these via SymbolSource.org (first got the request/suggestion this week)
Finally, if you want to see trace from a Windows build and are using the release packages from nuget then you can do this by overriding CreateDebugTrace() in your Setup.cs file - e.g. try:
protected override IMvxTrace CreateDebugTrace()
{
return new MvxDebugTrace();
}
This will also allow you to add some debug trace to your Core code if you want to using:
Mvx.Trace(format, args...)
Mvx.Warning(format, args...)
Mvx.Error(format, args...)
Perhaps, you forgot about adding ViewModel type to your generic MvxPhonePage.
Try this:
public partial class GridCategoryView : MvxPhonePage<GridCategoryViewModel>
I have created a new classes like following
[Order(Before = "High")] [Export(typeof(ICompletionSourceProvider))]
[ContentType("JavaScript"), Name("EnhancedJavaScriptCompletion")]
internal sealed class JavaScriptCompletionSourceProvider
: ICompletionSourceProvider
{ }
And the CompletionSource
internal sealed class CompletionSource : ICompletionSource, IDisposable
{
public void AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets)
{
}
public void Dispose()
{
}
}
These are both Added to a Visual Studio Package project.
So when I try to debug (with F5) I can see the debugging symbols are loading and the debugging stops in the
protected override void Initialize()
{
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
base.Initialize();
}
However when I'm editing a .js file, and invoking the intellisense (with that . dot that is) the deubbger won't break into ICompletionSourceProvider nor ICompletionSource methods of my classes.
So my question are:
1-5 Questions about standard Javascript Intellisense addressed in this screencast http://screencast.com/t/TwDlnpfOV0bX
6 how can we extend the standard javascript intellisense with extra options?
7 Is it possible to have two ICompletionSourceProvider classes for the same ContentType?
The reason your extension isn't getting composed is you haven't added it as MEF component to in your .vsixmanifest. To add it,
open the .vsixmanifest designer by double clicking the file in your solution explorer.
click asserts
click "new" on the right-hand-side
choose "Microsoft.VisualStudio.MefComponent" as the type
choose "project in current solution
choose your extension project