I wanted to change the base class of all pages in my project. To do so, I've made a class which inherits from ContentPage and then in all pages I should add the namespace of the BasePage that I've made like so:
xmlns:pages="clr-namespace:MyApp.Pages;assembly=MyApp"
and change the default tag of the page
<pages:PageBase xmlns="http://xamarin.com/schemas/2014/forms"
My question is, Can't we put the namespace of the BasePage somewhere like app.config in order not to repeat it for each page?
Related
I would like to have a shared UI project with common interface for other apps, so I don't have to copy/paste the same _Layout.cshtml between all apps which need same UI.
After using this question as reference and this article I have created shared Razor Class Library project. And when I reference this project via NuGet, the _Layout.cshtml in this shared project gets called and renders header with navigation.
But my problem comes then if I want to add some extra HTML to header. Let say I have drop down with some link to main landing page, to user setting, some administration page and etc. But how could I add some extra navigation links specific to concrete app next to all common links? Is there a way to inject HTML? Or maybe to pass some DTO model to this _Layout.cshtml?
Dump image below to help you to see what I try to achieve.
There's two possible approaches. First, you can simply call a partial in your layout:
<partial name="_HeaderExtra" />
Then, just add an empty partial view to the RCL, so it's satisfied, i.e. _HeaderExtra.cshtml. Finally, in your actual application, create the same partial view in the same location as the one in the RCL, and add whatever extra HTML you want there. When the partial is pulled into your layout, it will looking your project first, before falling back to the RCL.
The second option is to use sections. Sections are a little bit more strict, and you must remember to always reimplement them if you do any view inheritance. Essentially, in your layout, at something like:
#await RenderSectionAsync("HeaderExtra", required: false)
Then, in any sublayouts or views:
#section HeaderExtra
{
<!-- add something here -->
}
If you've got a sublayout and you want to be able to further customize this section in views, then you need:
#section HeaderExtra
{
#await RenderSectionAsync("HeaderExtra", required: false)
<!-- add something here -->
}
I am new to Xamarin development. I created new Xamarin XAML App(Xamarin.Forms Portable). In Portable Project there where MainPage.Xaml by default. To create MVVM Model I created three new Folders- Views, ViewModels, and Models. Now I added new MainPage.Xaml in Views folder and was going to delete the default MainPage.Xaml page. But here I see some difference in both pages. The default MainPage.Xaml have xmlns:local="clr-namespace:Test" but the new MainPage.Xaml does not. Again the new MainPage.Xaml have <Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" /> but the default one does not. The screenshots are:
What does these MarkUp mean.Why there is a difference. Does something needs to be changed. Can I delete the default MainPage.Xaml or should i copy it in Views.Does I need to copy the Markup from the default Page to the new one. If so why?
Thanks in advance
Both pages are identical, and will display in the same way.
On the second, there's an additional Xml namespace declaration:
xmlns:local="clr-namespace:Test"
It's only a declaration. You could remove it, or add it to the other page without effect. It's purpose is to be able to reference custom views declared in the current assembly and in the namespace (c# namespace, this time) Test, like this:
<ContentPage
...
xmlns:local="clr-namespace:Test"
x:Class="Test.MainPage">
<local:MyAwesomeView />
</ContentPage>
Awesome that you have decided to start with Xamarin and Xamarin.Forms!
While I understand you might be having these questions, this is some very basic XAML knowledge. The short answer is: you don't need to worry about it.
The long answer:
The reason that there is a difference in these pages is simply because it's just a template and whoever at Xamarin created the template for the project can be a different person than who created the template for a new XAML page. So they solved it different ways. Or maybe he had a good/bad day, who knows.
The Label in the first page is simply there to show you how to get started and so you won't start with an empty screen.
The extra namespace xmlns:local="clr-namespace:Test" is actually redundant in this new page but is already there so you can use the classes in your project.
It is actually the equivalent of the using list at the top of your classes. So whenever you need something from a different namespace you have to declare it there. So if you create a folder 'Controls' you can add a attribute xmlns:controls="clr-namespace:Test.Controls".
Note how I changed local to controls, this is the prefix you will use to define your instance. Also I have added the right namespace Test.Controls. Now if you want te show something on screen, in your XAML from the controls namespace, go like this:
<ContentPage xmlns:controls="clr-namespace:Test.Controls" x:Class="Test.MainPage">
<!-- some stuff here -->
<controls:ReusableControlHere />
</ContentPage>
Where ReusableControl can be your own version of a Label, Button or virtually anything.
I am working on an MVC 4 website that makes use of areas, lets call it 'MyMVC'.
As in most MVC projects there is a folder called 'Models' in the root of the website.
Inside this 'Models' directory there is a class called 'MyViewModel.cs' which contains a public class called 'MyViewModel' with a namespace of 'MyMVC.Models'.
Now, in one of the areas, call it 'Area1', there is also the typical MVC structure that also contains a directory called 'Models'. It also contains a class 'MyViewModel.cs' which also contains a class called 'MyViewModel', this time with a namespace of 'MyMVC.Areas.Area1.Models'.
Inside a view I am working on that is inside of the 'Area1\Views' directory I have at the top:
#model MyMVC.Areas.Area1.Models.MyViewModel
#using MyMVC.Areas.Area1.Models
When I go to reference the the MyViewModel like so, for example:
MyViewModel mvm = new MyViewModel();
I get an ambiguous error and it thinks I am referring to the other MyViewModel class although as you can see I have clearly specified with the #model directive and the #using directive which one I am referring to.
Can anyone explain what the ambiguity is?
Can anyone explain what the ambiguity is?
The ambiguity is not in your view. It's in your controller code:
MyViewModel mvm = new MyViewModel();
If in this controller you have both:
using MyMVC.Models;
using MyMVC.Areas.Area1.Models;
it's more than obvious that the C# compiler has no way of knowing which class you are referring to. You could remove the ambiguity by fully specifying the name of the class:
var mvm = new MyMVC.Areas.Area1.Models.MyViewModel();
UPDATE:
You might also have the namespace referenced in the <namespaces> section of your ~/Views/web.config file which is effectively bringing it into scope globally in all your views.
I'm working on styling the breadcrumb module.
Am I able to remove this class: RadSiteMap? I'd like to add my own styles to it.
I'm not sure you can remove that particular class, because I believe it is automatically generated by the control as it renders (you'd have to inherit from it and override this behavior, and even then I'm not sure it's possible).
your best bet is to use CSS to override that class properties. What you can do however, is use an external template (http://www.sitefinity.com/blogs/joshmorales/posts/josh-morales-blog/2011/05/10/mapping_external_templates_for_sitefinity_4_widgets) which will allow you to change the default CSS styles applied to the control (for breadcrum it has a wrapper class of "sfBreadcrumbWrp" and label class of "sfBreadcrumbLabel"
These are defined right in the template and can be changed as needed.
I hope this is helpful!
I have the following problem:
I have a class A that extends s:Panel.
I have a class B that extends A
<!-- Class A -->
<s:Panel xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" >
<s:Label text="A" />
</s:Panel>
<!-- Class B -->
<controls:A >
<s:Label text="B" alpha="0.3" />
</controls:A>
my intuition tells me that both texts should be shown, but I cannot make the text in A show.
thanks,
You can't add children twice to UIComponent. So Class A extends Panel, and adds a label to children array inside the Panel instance. And B extends A, but you can't add more children again. This is just a limitation of MXML. In theory you could do this, but Flex will throw an exception when you do this.
However, there are ways to work around this. You have to plan for this type of extension in Flex when designing the base class. This referred to a Template Component. The base class will serve as the template that will allow subclasses to specify pieces of the UI and the base class will wrap around those components. Overall I find this technique very important for creating reusable views that other users can be customize.
Check out this article on how you might do this:
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf68a49-7ffa.html
You can even add metadata [DefaultProperty] metadata tag to the base class so your users have the illusion they are adding to the children array just like default MXML does.
http://dispatchevent.org/mims/flex-manual-blues/