I'm making app using with Xamarin.forms.
I had my own renderer linked with ContentPage.
And I added a solution someone made on my solution because I need his function.
Problem is that it has a renderer linked with ContentPage too.
So Only One renderer works now. (only one OnAppears fired)
Of course I could do hand merge those two function.
Is that how it's done?
Any better solution?
Thanks.
If you want to have both behaviours then you will probably need to merge them. There's no way of telling which one it will use when the same type is referenced by both. However it always picks the most specific element type. That's why when you need more control you're probably better off subclassing ContentPage and attaching your own renderer to the subclass instead. Your content pages would then inherit from the subclass instead of the default ContentPage. That way other renderers can't get in the way either.
Related
I'd like to draw a proper, modern animated focus ring around a control, which according to Q&A 1785, should be a simple matter of overriding the -drawFocusRingMask and -focusRingMaskBounds methods.
Trouble is, for this project I have to use Xojo, which can declare and invoke Cocoa methods, but doesn't give me any opportunity to actually create my own view subclass.
So, is there any way to get a proper focus ring without making an actual subclass? Some other methods, perhaps introduced after this 10.7 tech note, that get the job done? Or some sneaky way to inject a method into an existing class at runtime?
As one comment suggested, class_addMethod() would be right if you want to add an optional protocol method. The public macoslib project has some code that shows how to do that, just search for that name.
However, if the function is already implemented, then you cannot add another. In that case method swizzling is the solution. It's a common method to replace a selector'd function address with another, and then call the original one.
I don't seem to have an example in Xojo for that at hand, though.
Update
For standard Cocoa controls the simplest solution is to set the NSView property focusRingType accordingly (available in macoslib). Implementing drawFocusRingMask is only necessary for custom controls.
I am working on a Xamarin Forms app where I am struck with 2 issues
First:
I have my custom button renderer and it is working fine. Now I have included reference of another project which have it's own button render. In this case there are two renderer for button. Which will be called and how??
Second:
What if I want to make use of both of the renders?
What I have tried:
Inherited my renderer from the renderer of the referenced project, but it won't work.I am confused with registration of this two renderers.How to register my renderer if inherited from other one.
For your first question, likely whichever the compiler finds first will be the one which is used. However this is only based on observations, I haven't found any documentation to back this up.
If this is something you have to support, what you can do is remove the assembly attribute from the renderers in the referenced project and move them into the target project i.e.
Move the following from the Renderer:
[assembly: ExportRenderer(typeof(CutomButton), typeof(MyApp.Renderers.CustomButtonRenderer))]
To say, the iOS Target project and place it on top of the AppDelegate class.
This means you will have several of these lines in the AppDelegate, but you can control which renderer you use i.e. ones in the library (if you can ensure they don't contain the above decoration) or ones in your own code.
For your second question, always create a new class that inherit XF's control, so that the control and renderer would be one-one relationship.
[assembly: ExportRenderer(typeof(Button), typeof(MyApp.Renderers.CustomButtonRenderer))] //bad
[assembly: ExportRenderer(typeof(CutomButton), typeof(MyApp.Renderers.CustomButtonRenderer))] //good
So I have this timer app that I am developing, and there is a setting in it to change from minutes:seconds to hours:minutes:seconds. This means that I need to adjust the UI of the app once the setting is changed. Considering I have constraints on the UI already, how could I do this?
When it is set to minutes:seconds, it displays this:
minutes:seconds
and then when it is set to hours:minutes:seconds, I want the UI to look like this: hours:minutes:seconds
Basically I would like to know the most efficient way to change the UI of the app when an action occurs. Thank you so much in advance!
Create two custom classes -
MinutesView
HoursView
Both will be inheriting from UIView. For each ofttimes classes you need their content which is their subviews. You can do that either programatically or via XIBs. It doesn't really matter.
Inside these subclasses implement the layout with two or three subviews.
Both classes will also have a time variable. Implement a property observer on both. Once a new time is set, update the labels that represent time digits.
Once you have both working. Put them both into your main scene, lay them out however you wish.
The only thing you will have to do when switching between two modes is set the .hidden property on both. Obviously when one is hidden the other one is not and vice versa.
I have to access user control in different view. But I get the inaccessible due to control's protection level error. I searched quite for a long time but I can't find anything. Please help me.
Thanks.
There are two possible solutions I can think of:
Hard-way: Create a custom MultiPage with custom renderer for every platform (https://developer.xamarin.com/api/type/Xamarin.Forms.MultiPage%601/ and https://developer.xamarin.com/guides/cross-platform/xamarin-forms/custom-renderer/)
Make a custom ContentView with all you layout elements and bindable properties and add it to all you pages (and set the correct bindings). Something like this: https://stackoverflow.com/a/32610859/5064986
(I think) I had a similar situation. I found that a ListView was inaccessible due to protection level in the code behind to the xaml. I added this to the ListView element.
x:FieldModifier="public"
Based on this in docs.
First time building a user interface, had a few general questions
1) Does it really matter if you drag and drop view objects into view controller.. or if you programmatically add subviews and specify frames and fonts? What's the better approach to take?
2) In the programmatic approach, I end up guessing frame values, (x,y) points, and then checking in simulator if I like it. Is this the right approach, or are there faster, better ways to build out the UI? Maybe methods I'm not aware of?
3) Any useful tutorials/pointers in the right direction on how to get started?
Thanks!
1) Both approaches are fine, but the Interface Builder is usually better if you have a more static UI. In a more dynamic app (where views appear and disappear, or if you use UIViewController containment), you need to add/show/hide some of the views in the code. Even in that case you can design individual views in the IB, to make sure they look good, and then instantiate and display them in the code.
2) If you design your views in the IB, then the problem of guessing the sizes largely disappears. In some cases it can be useful to have an empty view added in the IB, which acts as a placeholder for your dynamic content. Then, when you add a view to it in the code, you just use the superview's dimensions so your view fills the placeholder.