Implementing UWP flyout splitview using masterdetailview in prism? - xamarin.forms

I am a complete noob to xamarin :)
So was wondering if someone could point me to right resources.
To be short, I want to implement something like this in prism using Xamarin MasterDetailPage.
Using the master detail sample here, the hamburger menu doesn't act as a fly out.
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="HelloWorld.Views.MyMasterDetail">
<MasterDetailPage.Master>
<ContentPage Title="Default">
<StackLayout>
<Button Text="ViewA" Command="{Binding NavigateCommand}" CommandParameter="MyNavigationPage/ViewA?id=A" />
<Button Text="ViewB" Command="{Binding NavigateCommand}" CommandParameter="MyNavigationPage/ViewB?id=B" />
<Button Text="ViewC" Command="{Binding NavigateCommand}" CommandParameter="MyNavigationPage/ViewC?id=C" />
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>
</MasterDetailPage>
Right now, though there is enough space, it shows something like
(just as a sample, I am not using SplitViewMenu at all)
I need icons/some small text to show initially and on clicking hamburger, it should expand (you know just like the first link/ groove music app behavior).
Tips?

Right now, though there is enough space, it shows something like
In my experience, if you have assigned the Symbol property for SimpleNavMenuItem, the possible reason is you haven't imported the Themes file Generic.xaml under Themes folder
This file includes templates, styles for custom controls. For example, for NavMenuItem's template, FontIcon's Glyph property needs to be assigned correctly here:
<DataTemplate x:Key="NavMenuItemTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="48" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<FontIcon FontSize="16" Glyph="{Binding Path=SymbolAsChar}" VerticalAlignment="Center"
HorizontalAlignment="Center" ToolTipService.ToolTip="{Binding Path=Label}" />
<TextBlock Grid.Column="1" Text="{Binding Path=Label}" VerticalAlignment="Center" />
</Grid>
</DataTemplate>
While SimpleNavMenuItem class's SymbolAsChar property is based on Symbol's value:
public sealed class SimpleNavMenuItem : INavigationMenuItem
{
......
public Symbol Symbol { get; set; }
public char SymbolAsChar => (char) Symbol;
......
}
And if you still can make it work, please share a demo:)

I've sort of been looking for something like this myself since I can't hide the NavigationBar shown in the Master page of the MasterDetailPage when i run it on a Windows 10 Mobile device (I can hide for PC though). So basically, I'm looking into eventually building my own version of the MasterDetailPage.
Since I have not built it yet, I can't tell you exactly how to achieve what you're asking, but I do know that it will require you to either:
Write your own custom renderer for MasterDetailView or,
Write a new control and its renderer
In both cases, your renderer will involve creating and manipulating a new SplitView (which is the native UWP control that your SplitViewMenu example is extending). There's a tutorial for creating the actual UWP control here. If you havent learned about Xamarin's renderers yet, they are the "Translator" and "Interpreter" between a Xamarin.Forms control and a given platform's native control. I suspect Xamarin will eventually rewrite their MastDetailPage renderer for UWP to use a SplitView as a base, but who knows when that will be. Xamarin also has an open source SDK for Xamarin.Forms (as well as the others) on GitHub so you can study the MasterDetailPageRenderer for UWP.

Related

CarouselView swiping is Buggy

I'm relatively new to Xamarin Forms. I'm trying to have a view that allows me to swipe left/right between different pages with a page indicator at the bottom. I'm using CarouselView, as suggested by the internet, and it seems to work. But, the selected page is very buggy. Sometimes, swiping to the next page causes it to snap back to the previous page. Sometimes, it stays on the current page. Sometimes, it works correctly. I observe the same behavior on both Android and UWP. Although, it appears to be a little worse in UWP than Android.
It seems the index for the current page is getting mixed up somehow. Here is my XAML:
<ContentPage.Content>
<StackLayout>
<CarouselView x:Name="Pages" IndicatorView="{x:Reference ActivePageIndicator}">
<CarouselView.ItemsSource>
<x:Array Type="{x:Type ContentView}">
<views:TroubleshootingPage />
<views:StatusPage />
<views:ContactInfoPage />
</x:Array>
</CarouselView.ItemsSource>
<CarouselView.ItemTemplate>
<DataTemplate>
<ContentView Content="{Binding .}" />
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
<IndicatorView
x:Name="ActivePageIndicator"
IndicatorColor="LightGray"
SelectedIndicatorColor="Green"
IndicatorSize="16"
IndicatorsShape="Circle"
HorizontalOptions="Center"
Margin="4"
/>
</StackLayout>
</ContentPage.Content>
I've tried using different types of views in the ItemsSource list. But, I still get the same effect.
Is there something I'm doing wrong? Something I'm missing? A bug in CarouselView?
Thanks.

mvvmcross xamarin.forms PictureChooser

I am trying to develop a photo app using the PictureChooser plugin. I see that the sample uses Xamarin.iOS. I've googled for examples where the plugin uses Xamarin.Forms but can't find any. I understand how binding works for labels, text editors, and buttons; however, the binding btw the page's image control and the viewmodel's byte[] has got me stomped.
DAA.UI project:
In CameraPage.XAML:
<Image x:Name="MyImage"
Source="{Binding Bytes, Converter={StaticResource InMemoryImage}}"
Aspect="Fill"
HeightRequest="{OnPlatform iOS=300, Android=250}"
WidthRequest="{OnPlatform iOS=300, Android=250}"
HorizontalOptions="Center" />
In App.XAML:
<?xml version="1.0" encoding="utf-8" ?>
<Application
x:Class="DamageAssessmentApp.UI.App"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="clr-namespace:MvvmCross.Forms;assembly=MvvmCross.Forms"
xmlns:resources="clr-namespace:DAA.UI.Resources"
xmlns:local="using:DAA.UI"
xmlns:nativeValueConverters="using:DAA.UI.NativeValueConverters">
<Application.Resources>
<!-- Application resource dictionary -->
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<resources:Colors />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<nativeValueConverters:NativeInMemoryImageValueConverter x:Key="InMemoryImage"/>
</Application.Resources>
</Application>
Value Converter file:
using MvvmCross.Forms.Converters;
namespace DAA.UI.NativeValueConverters
{
public class NativeInMemoryImageValueConverter : MvxNativeValueConverter<MvxInMemoryImageValueConverter>
{
}
}
The compiler can't find MvxInMemoryImageValueConverter in the value converter file.
If you are using MVVMCross you should find an example that works with Xamarin.Forms, in which case a good place to start it's their Github.
Or you have to implement it in each platform and use a DependencyService to get the implementation
Other Alternatives
Xamarin Community Toolkit
Another alternative for a camera App is Xamarin Community Toolkit Camera View. In that same link there is an example. But there are more examples in their Github. This is fully compatible with Xamarin.Forms and brings a little more control over the CameraView
Xamarin.Essentials
Xamarin.Essentials offers the MediaPicker that let's the user upload a photo from the gallery or take a new one. But the action of the photo in handled by the OS, so for you it's like a black box. You call the function, and get the photo.

CollectionView issue mixing grouping with GridItemsLayout

I'm trying to implement a Xamarin Forms CollectionView using Grouping and GridItemsLayout vertical mode and Span="2". I make the grouping work without problems, but when I add the GridItemsLayout with the Span set to 2 columns, it does not behave as it should. Still showing the collection as 1 column.
<CollectionView
Grid.Row="1"
IsVisible="{Binding VisibleCollection}"
IsGrouped="True"
ItemsSource="{Binding Accounts}">
<CollectionView.GroupHeaderTemplate>
<DataTemplate>
<Label
FontSize="16"
Text="{Binding Name}" />
</DataTemplate>
</CollectionView.GroupHeaderTemplate>
<CollectionView.ItemsLayout>
<GridItemsLayout
Orientation="Vertical"
Span="2"
VerticalItemSpacing="10" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Label BackgroundColor="Red" Text="TEST" />
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Label "TEST" still showing in 1 single column, and I want it to be shown as 2 columns:
TEST TEST
instead of:
TEST
TEST
Anyone knows how I can make it possible with GridItemsLayout? btw, this issue is happenning on UWP
Label "TEST" still showing in 1 single column, and I want it to be shown as 2 columns
Thanks for taking time to report this problem, for my testing the problem occurs in Xamarin Forms earlier version, and it is fixed in current stable version. Please update your Xamarin.Forms Nuget Package version to 4.5.0.530 . And please note CollectionView is available on iOS and Android, but is only partially available on the Universal Windows Platform. For more info please refer this document.
The problem comes when the collection view is initially "hide" and switching visibility.
Xamarin forms issue: https://github.com/xamarin/Xamarin.Forms/issues/9079
Try to set GridItemsLayout from main thread.
Example
Device.BeginInvokeOnMainThread(() =>
{
BannerList.ItemsLayout = new GridItemsLayout(2,ItemsLayoutOrientation.Vertical);
BannerList.ItemsSource = ImageList;
});
This is worked for me.

How can I use partial views in Prism?

I have Prism 7.1 with Xamarin Forms 3.5. I can't get partial views to work correctly.
The consuming view has this up the top
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
prism:ViewModelLocator.AutowireViewModel="True"
xmlns:converters="clr-namespace:MapManPrism.Converters"
x:Class="MapManPrism.Views.WelcomeWizardPage"
xmlns:mvvm="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
x:Name="wizard"
Title="Welcome" xmlns:cv="clr-namespace:PanCardView;assembly=PanCardView"
xmlns:cvi="clr-namespace:PanCardView.Controls;assembly=PanCardView" xmlns:views="clr-namespace:MapManPrism.Views">
As you can see I am giving the consuming page a name (wizard).
I then have a carouselview that has several views in it
<cv:CarouselView SelectedIndex="{Binding CurrentPage}" IsPanSwipeEnabled="false" IsUserInteractionEnabled="false">
<cv:CarouselView.ItemsSource>
<x:Array Type="{x:Type View}">
<ContentView Padding="10" Margin="10">
...
</ContentView>
<ContentView>
<Frame>
<views:PublisherDetails mvvm:ViewModelLocator.AutowirePartialView="{x:Reference wizard}"></views:PublisherDetails>
</Frame>
</ContentView>
In my app.xaml.cs I have this line
ViewModelLocationProvider.Register<PublisherDetails, PublisherDetailsViewModel>();
But I can't navigate to the consuming page when its set up like this. Removing "mvvm:ViewModelLocator.AutowirePartialView="{x:Reference wizard}"" makes it work, but obviously the view model for the partial view doesn't get wired up.
How can I fix this? Or, is there a way to manually connect the partial view's view model to see if that fixes it?

What is the best way to create the MasterDetailPage menu items in Xamarin.Forms

I'm using a MasterDetailPage in my Xamarin.Forms application.
To creat the menu items, I use buttons
<MasterDetailPage.Master>
<ContentPage Title="Menu">
<StackLayout Orientation="Vertical">
<Button Text="Club-House" Command="{Binding ClubHouseCommand}" />
<Button Text="Parcours" />
<BoxView VerticalOptions="CenterAndExpand" />
<Button Text="A propos" Command="{Binding AProposCommand}" VerticalOptions="End" />
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>
Is there a better way to do it ? I was thinking about something more menuish like MenuItem or else.
Thanks
There is nothing standard for implementing a menu in the Master page.
You can use
ListView
StackLayout
Grid
Or a combination. StackLayout and ListView will most likely be your best options. Personally I go for a StackLayout because it's quicker to code and render than a ListView, which may come with more issues than advantages. However if I have a large menu (which I try to avoid), ListView may be quicker to code. But ListViews are generally meant for dynamically loaded data, not static.
As for the elements, the most common will be
Button
Label
While buttons are designed for clicking, sometimes I move to label's if I don't want to have to undo all the default styling, and use the TapGestureRecognizer.
You can create a new User Control for a menu item, to avoid code replication.
All up, there is no standard. Make it easy to code and understand, and quick to render. How you do that, depends on your requirements.

Resources