What is the proper way to create control in Xamarin Form PCL? - xamarin.forms

What is the proper way to create control in Xamarin Form PCL?
In my class library I have "control" class not derived from any View, just a layout with some labels, scrollviews, logic etc.
I am using it in my pages in the same PLC in several places.
My question is - what is the proper way to wrap this "control" and use it in PLC pages?
I ended up having this control class to expose its root layout where I add all the child elements and subsequently add this layout to the children of page layout. This makes this class to be some sort of a builder of a part of UI of a page.
It looks like that using "View" as a base class requires me to add custom renderers to Android and iOS projects
which I don't need to do - all my UI functionality fits into PCL withot the need for any custom work.
I have a feeling that I am not doing it the right way.
Advise and/or link to the documentation on how to properly do it will be greatly appreciated.

It seems to me that you're actually hurting yourself by not wanting to use a View as a base class. I commonly use ContentView as a base class to create my own controls and it works great without the need for a custom renderer since ContentView already has its own renderers in iOS and Android. Something like this should do the trick.
public class MyContentView : ContentView
{
private Layout createLayout();
public MyContentView()
{
Content = createLayout();
}
}

Related

How to add android attributes like android:id on Xamarin Forms(XAML)?

I've already tried setting android attributes like contentdescription by creating a custom element and setting the attribute on the renderer using the control.
Control.ContentDescription = ((MyEntry)e.NewElement).ContentDescription;
Is there a way to do it on the XAML rather than custom renderer?
Another, how can I set the android:id attribute? I've tried it change it on custom render but I think it's not working.
Sidenote: I'm using a RealWear device which can generats a script which has the UI elements of the page. The UI elements will contain the id attribute if it exists.
Hello and welcome to StackOverflow.
you can't add Android descriptions to xamarin forms elements.
Xamarin forms abstracts the ui to a non-native format (xaml) and converts the abstract definition of an element to a native one. However this happens "under the hood" and therefore you don't have direct access to that from xamarin.forms.
What you could do is, if you really need an element with a set id, you can either find a way to hack in your id using a custom renderer or you create and embed native elements.
For the latter please see the following microsoft article, which is a bit too much to include within this answer: https://msdn.microsoft.com/en-us/magazine/mt790186.aspx

In a tabpage GUI Extension, what does the ext:pagetype node do?

I have a GUI Extension adding a Tab (ext:tabpage) to View.
What does the ext:pagetype node do? I have been using Namespace:Name like the following. Are there other options for the value?
<ext:pagetype>RC.TabExtension</ext:pagetype>
It allows you to have a specific JavaScript implementation for that tab.
If you specify the full name of a JavaScript class and it implements the Tridion.Controls.DeckPage interface, it will use that implementation for the tab.
If it's not a class or it doesn't implement the interface, it will just use the default implementation.
(Tabs inherit from Decks, in case you are wondering)

How to create "Available field" properties in my own property?

I have created a class inherit from StateManagedCollection.
It has got a few class as Columns like GridView.
But I can not select which filed I want to select from.
It should look like the picture below in design.
But mine is the one below:
I have written the property as below:
[Description("A collection of ToolBarItem's ")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(System.ComponentModel.Design.CollectionEditor), typeof(System.Drawing.Design.UITypeEditor)), PersistenceMode(PersistenceMode.InnerProperty)]
public virtual Items Items
{
}
Can anyone help me out?
GridView columns collection uses a custom UI Type editor to show this interface. The in-built ASP.NET CollectionEditor will not show the required UI. Further in your case, CollectionEditor may not work if the collection's item type is a abstract class.
Solution is to build your own custom UI Type editor - basic steps are
Inherit from System.Drawing.Design.UITypeEditor.
Override GetEditStyle method to inform the property browser that you will launch modal form.
Override the EditValue method to launch your custom UI form.
Build the custom UI Form.
See a couple examples here (see sample for TagTypeEditor) and here.

Difficulty copying/extending singleton manager class

I want to extend or copy the PopUpManager class to add the ability to keep track of the number of windows.
I just want to add a simple windowCount++ when a window is added and windoCount-- when it's removed.
the problem is PopUpManager is a Singleton class... I wasn't able to make it work properly by extending it. And now I have tried to copy the code from the PopUpManager.as file and just add my variable to the end of its functions. It doesn't seem to be working though since it says my properties are undefined even though they are declared above the constructor.
I am thinking I would have to make a copy of the PopUpManagerImpl.as since that's wehre it seems much of the business resides (PopUpManagerImpl extends EventDispatcher implements IPopUpManager) would that allow me to have access to the variable? and should I ignore the manager and just put it in the implementation class?
here is a link about Using the Flex Singleton register, which helped me out when finding myself in the same situation.
I hope you can inspire from that too.
You likely didn't declare yours properties as static. The PopUpManager uses all static methods - this is why working with it you use syntax like:
PopUpManager.createPopUp(...
instead of
var popUpManager:PopUpManager = new PopUpManager();
popUpManager.createPopUp(...
This means that any variables declared in the PopUpManager need to also be static so as to be accessible at the class level.
public static var windowCount:int

How to hack private static field in Flex?

Is there a way to change private static field of an alien class?
For example:
package mx.managers {
public class TooltipManager ... {
private static var _impl:IToolTipManager2; // <- assign my own value here
...
}
}
In Java it is possible to do it using Reflection API. What about Flex?
No, that is not possible.
If you are looking into changing the implementation of the TooltipManager, have a look at the Singleton class in the Flex SDK. You'll need to create a custom implementation and register it via the Singleton class before the application initializes. The best is to override the application preloader and do the registration there.
Well, if you feel like you can handle the extra responsibility, you can monkey patch the class by copying the source into your own source tree with the same package and apply the necessary modifications. That way the flex compiler will use your implementation rather than the SDK implementation.
This technique is sometimes used as a last resort to fix issues which cannot be fixed otherwise. Drawbacks include issues such as forwards compatibility and unintended side effects in the same or other classes dependant on the class your editing.

Resources