Xamarin Forms XAML Design Instance - forms

Is there a way to enable design context in Xamarin Forms XAML pages to enable intellisense? It works in WPF but for years I couldn't get it to work in Xamarin Forms.

So if you compile your xaml by setting the attribute in code somewhere, and then include the xaml snippet below, you can use design time data contexts and get the intellisense.
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace MySpace
{
public partial class App {}
}
<Page
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d ="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=list:TestViewModel}"
xmlns:list="clr-namespace:PolyhydraGames.Test.ViewModels"
.../>

Normally you should get it by default. Otherwise try Ctrl + Space. You do not need any additional code. Note it will not show you the intenseness for binding objects but all the design time elements.

Related

What is the use of AppShell.xaml in MAUI?

I went through the official docs, but I still need to know the in-depth use of AppShell.xaml and the App.xaml files and how they differ from each other in the MAUI.
PS: This post is intended to act like a documentation in future for beginners struggling with MAUI.
AppShell provide the navigation for the app.
The visual hierarchy of a .NET MAUI Shell app is described in the subclassed Shell class, which the project template names AppShell. A subclassed Shell class consists of three main hierarchical objects and they are all in the AppShell.xaml file:
FlyoutItem or TabBar. A FlyoutItem represents one or more items in
the flyout, and should be used when the navigation pattern for the
app requires a flyout. A TabBar represents the bottom tab bar, and
should be used when the navigation pattern for the app begins with
bottom tabs and doesn't require a flyout. For more information about
flyout items, see .NET MAUI Shell flyout.
Tab, which represents grouped content, navigable by bottom tabs.For more information, see .NET MAUI Shell tabs.
ShellContent, which represents the ContentPage objects for each tab.
For more information, see .NET MAUI Shell pages.
App.xaml and App.xaml.cs:
App.xaml is where you declare resources that are used across the
app.
App.xaml.cs is the code-behind file for App.xaml. Like all
code-behind pages, it contains a constructor that calls the
InitializeComponent method. You don't write the InitializeComponent
method. It's generated by Visual Studio, and its main purpose is to
initialize the elements declared in the XAML file.
App.xaml.cs is the entry point for your app.

How to use a FreeMarker template in a Magnolia App?

I'm using Magnolia 5.4 and have developed an app following the documentation:
https://documentation.magnolia-cms.com/display/DOCS54/Apps
The app is being rendered correctly in the magnolia shell.
Opening the app shows a «Hello World» message as described in the documentation:
https://documentation.magnolia-cms.com/display/DOCS54/Programming+an+app#Programminganapp-MainSubApp
I've removed the unnecessary code and ended up with this:
public class HelloWorldMainSubAppViewImpl implements HelloWorldMainSubAppView {
private VerticalLayout layout = new VerticalLayout();
private Listener listener;
public HelloWorldMainSubAppViewImpl() {
layout.setMargin(true);
layout.setSpacing(true);
layout.addComponent(new Label("Hello World!"));
}
#Override
public Component asVaadinComponent() {
return layout;
}
}
Instead of using the Label component I would like to use a FreeMarker template where I define a custom view.
Having read through the documentation I haven't figured out yet how to do this.
Here is the solution to my problem, based on the previous work.
This is the «EmbeddedPageSubApp» approach as described under «Custom App»
Create a regular page somewhere in your navigation.
Open the Configuration app, go to /modules/<APP_NAME>/apps/<APP_NAME>/subApps/main and add a url property to the mainSubApp with an absolute path to the previously created page.
Change value of the class property /modules/<APP_NAME>/apps/<APP_NAME>/subApps/main to info.magnolia.ui.framework.app.embedded.EmbeddedPageSubAppDescriptor
Change the value of the subAppClass property to info.magnolia.ui.framework.app.embedded.EmbeddedPageSubApp
If you don't want that page to be visible restrict its access within 'superuser' group / role so that only administrators can use it.
This binds that with an iframe. You should choose a blank template since the navigation elements of the embedded page are visible within the app.
I might be wrong here but to my knowledge Freemarker is only used to create templates and unfortunately limited to it. https://documentation.magnolia-cms.com/display/DOCS60/Template+scripts
On the other hand, What you want to do is to develop your custom app and here is an example of how to do that.
https://documentation.magnolia-cms.com/display/DOCS54/My+first+content+app
Also, if you are motivated to move to latest Magnolia version, you can define your custom app pretty easily using Content Types.
Hope that helps,
Cheers,

How to bind IsSelected Property of ListBoxItem with Mode Two way using WinRT Xaml Toolkit in Windows 8.1

I have a Windows 8.1 Application
I am using WinRT Xaml Toolkit to bind my IsSelected Property to my ViewModel as the Binding is supported out of the box.
I have included the following Namespace
xmlns:Extensions="using:WinRTXamlToolkit.Controls.Extensions"
Here is the ListBoxItem of my XAML
<ListBoxItem Extensions:ListBoxItemExtensions.IsSelected="{Binding MyBool, Mode=TwoWay}">
<TextBlock Text="MyText" />
</ListBoxItem>
However I am unable to bind it TwoWay, the binding is working only from ViewModel -> View.
Is this a limitation of the Extension. If yes how do I achieve two way binding?
I would be very glad if someone can point me in the right direction.
Thanks in Advance.
You cannot do this, unfortunately.
You can, however two-way bind to the ListView.SelectedItem.
If you need more than one selected item, the WinRT Toolkit has BindableSelection: http://winrtxamltoolkit.codeplex.com/SourceControl/latest#WinRTXamlToolkit/WinRTXamlToolkit.Shared/Controls/Extensions/ListViewExtensions.cs
Best of luck!

Using mgwt for desktop and mobile applications

I have an application written in GWT. I want to be able to provide a subset of the same application for use when the site is opened in mobile browsers, and have been looking at mgwt as a way of achieving this.
The way I am expecting it to work is that I will augment my existing GWT application project with mgwt code (with some logic sharing) resulting in two entry points. My question is how to manage this given a single html page? I have seen the approach described in this article and was wondering whether that will work well with mgwt or whether there should be another pattern I should be considering?
I don't think you need 2 entry points. As kiran said above, you should reuse all the code except the view components. In case you used the GWT Activities and Places module, the view components should be completely decoupled from the rest of the code.
In this case you can use the the GWT.create method associated with the correct definitions in the module xml definition:
//in your entry point:
private IClientFactory clientFactory = GWT.create(IClientFactory.class);
//in your module xml definition:
<replace-with class="com.vv.xui.client.DesktopClientFactory">
<when-type-is class="com.vv.xui.client.IClientFactory" />
<when-property-is name="formfactor" value="desktop"/>
</replace-with>
<replace-with class="com.vv.xui.client.MobileClientFactory">
<when-type-is class="com.vv.xui.client.IClientFactory" />
<when-property-is name="formfactor" value="mobile"/>
</replace-with>
The form formfactor property can be defined as in this example:
https://code.google.com/p/gwt-cx/source/browse/trunk/gwtcx/gwtcx-core/gwtcx-core-client/src/main/resources/com/gwtcx/FormFactor.gwt.xml
In your IClientFactory you will have something like this:
public interface IClientFactory {
IHomeView getHomeView();
ISearchView getSearchView();
...
}
Where IHomeView and ISearchView are the view interfaces implemented by the desktop and the mobile versions. In my case the View implementations are UiBinder components that implement the associated view interface.
In your DesktopClientFactory you will have something like this:
public class DesktopClientFactory implements IClientFactory {
private static final ISearchView searchView = new com.vv.xui.client.view.desktop.SearchView.SearchView();
#Override
public ISearchView getSearchView() {
return searchView;
}
...
}
In this way you don't need different entry points for mobile and desktop and can share all the code except the view components.
That pattern in the link pointing to MobileWebApp on googlecode is correct. Basically you have UI view interfaces in GWT which stick to MVP pattern recommended on GWT. Then you can do different implementations of the UI Views based on the screen resolutions available. Obviously you don't want the same screen lay outs on desktop and mobile. So you will need to redesign your views for different form factors and then call the correct implementations based on the form factor the device. Since you already have a gwt application, you can create views for mobile using mgwt and reuse the code that you already created. But still you will have to create new views for mobile using mgwt, it wont be a straight forward replace.

GWT: formfactor dependent editor

I'm developing a web app for different formfactors. Each has its own client factory to create formfactor dependent views. Everythings works fine so far but I'm stuck when it comes to the Editor Framework.
To make use of the framework I have to declare a marker interface like so:
interface Driver extends SimpleBeanEditorDriver<User, UserEditor> {}
Since this happens in my formfactor agnostic activity I want the type UserEditor to refer to the actual implementation based on the formfactor, i.e. UserEditorPhone, UserEditorTablet, UserEditorYouNameIt.
To no avail I tried using deferred binding in module.gwt.xml:
<replace-with class="com.example.client.desktop.UserEditorDesktop">
<when-type-is class="com.example.client.view.UserEditor"/>
</replace-with>
Any ideas on what I'm missing and how to avoid having a one-to-one-relationship between formfactors and UserEditor-activities?
You'll want your formfactor-agnostic activity to only know about SimpleBeanEditorDriver<User, ?>, and move the Driver interface into each one of UserEditorDesktop, UserEditorTable and UserEditorPhone.
The activity will then ask a formfact-dependent object (e.g. its view, if you use MVP and the activity is the presenter) for an instance of the editor driver rather than using GWT.create() directly.
(I can give code sample if you detail how your code is organized: are you using MVP? is the editor your view? how's it instantiated? etc.)