Windows phone 8 - Include XAML in another XAML file - xaml

im currently developping a windows phone application and i was wondering if it was possible to include another XAML file in a XAML file.
I've heard about UserControl but im not really sure how I should use it.
Thanks.

There are 2 mechanisms that may provide the functionality you're looking for:
Subclassing
XAML pages can be subclassed. For example:
[xaml.cs (for subclass)]
public partial class SubclassPage : BasePage
[xaml (for subclass)]
<?xml version="1.0" encoding="utf-8" ?>
<BasePage xmlns="http://xamarin.com/schemas/2014/forms"
...
>
etc.
User control
https://msdn.microsoft.com/library/hh144799(v=vs.100).aspx
(skip to the section "Adding a new user control to the project")
Bottom Line:
If you want to include a XAML file in another because 2 pages are very similar, consider subclassing. Alternatively, if you find the same collection of elements is reused across multiple pages (perhaps copy-pasted), strongly consider refactoring it into a user control.

Related

Make Xamarin Forms default to compile all XAML

When I create a ContentPage in Xamarin Forms, the code behind partial class gets decorated with an [XamlCompilation(XamlCompilationOptions.Compile)] attribute. I know I can add an assembly level attribute for this, but is there any way to prevent the page level attribute being used besides explicitly removing it?
Say I decided to Skip most pages instead, I will have to go and change that attribute on every ContentPage.
PS: I have suggested this on Xamarin Customer Feedback. If this interests you, please check it out and give it a vote.
You should suggest this on the xamarin uservoice site and post a comment with a link to the suggestion so others can vote on it.
https://xamarin.uservoice.com/forums/144858-xamarin-platform-suggestions

Create and use global view in C# WP8 XAML

I was trying to digg something on this topic before, but have no luck. What I'm trying to achieve is pretty simple, but seems to be hard to achieve :-)
I have a WP8 app (C# XAML) and I need to implement global messages (something like toasts) which could be displayed across whole application no matter of current navigation processes. Such toast message(s) should be displayed even while user is navigating between pages. To use the built in toasts is not a way (in case some other solution exists) since I'm possibly in need to have more than one message displayed at the same time (each one is independent of another) and should disappear after specified period of time.
So, my question is. Is there any way how to implement and use some kind of global view instance which sits above all pages and can be called from any page?
All I found until now is the possible ability to use PhoneApplicationFrame, but I would like rather avoid that if possible. I'm still unsure if this is even the way it can be done, but I suppose so. Do you have any alternatives or assurance this is possible and only way to achieve this goal?
Thank you all for your time and answers.
You can have UerControl for the Functionality you are looking for. It is Control that has its own Seprate Xaml and cs file. You can call it from any page into your Project. UserControl provides the base class for defining a new control that encapsulates related existing controls and provides its own logic. You have a XAML file and C# class file for a user control. The class file extends the UserControl class and adds additional behaviours and properties. The XAML file encapsulates the composing controls, the styles, the templates, animations and whatever necessary to form the UI. Since it is a just composition, it is really easy to create. for more Reference you can go here Why and how to create a User Control in Windows Phone
I have ended up rolling my own custom navigation using a single master page. As such any global controls are instantiated once at startup. Navigations are called from my viewmodels and result in usercontrols being removed and added to the visual tree as necessary (using transition animations to give the impression of page navigation) This works but im not sure whether it is best practice and would appreciate some opinions and comments on this. Certainly it solves the problem of global views described.

separate header, content and footer in yii

I have a login form in my header section of the website. If user is logged in than insted of the login form user profile details will be shown. The question is how to separate header footer and content into different views and call them from one controller? Or maybe there is another solution...Thanks for help.
In your header view you could write something like this.
<?php if(Yii::app()->user->getId()): ?>
<?php $this->renderPartial('//world/_header_user')); ?>
<?php else: ?>
<?php $this->renderPartial('//world/_header_guest')); ?>
<?php endif; ?>
Using the Model-View-Controller (MVC) design pattern, the look of a Yii-based site is naturally controlled by the View files. These files are a combination of HTML and PHP that help to create the desired output. Specific pages in a site will use specific View files. In fact, the View files are designed to be broken down quite atomically, such that, for example, the form used to both create and edit an employee record is its own file, and that file can be included by both create.php and update.php. As with most things in OOP, implementing atomic, decoupled functionality goes a long way towards improving reusability. But the individual View files are only part of the equation for rendering a Web page. Individual view files get rendered within a layout file. And although I’ve mentioned layouts a time or two in my writings on Yii, it’s a subject that deserves its own post.
To be clear, layouts are a type of View file. Specifically, whereas other View files get placed within a directory for the corresponding Controller (i.e., the SiteController pulls from views/site), layout files go within views/layouts. But while the other View files are associated with individual Controllers (and therefore, individual pages), layouts are communal, shared by all the pages. Simply put, a layout file is the parent wrapper for the entire site’s templating system. I’ll explain
ypu can see more details
http://www.larryullman.com/2012/05/16/working-with-layouts-in-yii
The easiest way is probably to use a different layout, which you just switch on login. If not, showing partials / components based on Yii::app()->user->isGuest also works well.
Your default generated Yii application has a parent Controller in protected/components/Controller.php.
If you need to access additional parameters in layout, add public properties to Controller, set them in your child controller, and use them in your view/layout files.

How do you make a control reusable in different projects?

Is there a way to not put the project name in the Inherits attribute?
I am working with vb and I have multiple projects, that have multiple web pages.
In each of these projects I create controls that are reused in the web pages.
Each control I have is declared like this:
<%# Control Language="vb" AutoEventWireup="false" CodeBehind="MenuBarControl.ascx.vb" Inherits="**projectName**.MenuBarControl" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
When I want to copy the control into another project I have to change the **projectName**.
Having to change the project name for each project makes the code not reusable. Changes made to specific projects each time is not reusable.
I want to be able to omit the project name in the Inherits attribute.
When I do that now I get an error
Parser Error
Parser Error Message: Could not load type 'MenuBarControl'.
Just create a new project that includes all the controls, reference that from the web projects.
http://blogs.msdn.com/b/davidebb/archive/2005/10/30/487160.aspx
Basically, you create a DLL and include it in your other projects. Alternatively, you can modify a user control library. More info here: http://webproject.scottgu.com/CSharp/UserControls/UserControls.aspx

How to pass a value between Silverlight pages for WP7?

I've got a MainPage.xaml page a Detail.xaml page.
I've passed variables to the Detail.xaml from MainPage.xaml by using a static variable and referencing it in Detail.xaml (the detail page is acting like a dialog). However once I've updated the content of another object, I want to call a method in MainPage.xaml to refresh the content of that page using the updated object from the Detail.xaml page.
I assume I am not using the correct paradigm for this and should probably be using MVVM or something but I'm not familiar with the implementation and was hoping there was a simple way to do this?
Can you load the content from the static into your control in the OnNavigatedTo?
You can make a method in your main page to do that job and call that.