Skip to content

Instantly share code, notes, and snippets.

@cpboyd cpboyd/AttachmentsPage.xaml Secret
Created Jul 13, 2017

Embed
What would you like to do?
Xamarin.Forms Embedding StaticResources issue
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
xmlns:cells="clr-namespace:Example.Controls.Cells"
xmlns:theme="clr-namespace:Example.Controls.Theme"
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:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific"
x:Class="Example.Views.Settings.AttachmentsPage"
Title="Attachments" BackgroundColor="{StaticResource DarkBackgroundColor}">
<ContentPage.Content>
<theme:CustomTableView Intent="Settings" BackgroundColor="{StaticResource DarkBackgroundColor}">
<TableRoot>
<TableSection Title="Report">
<SwitchCell Text="PDF" On="true" />
</TableSection>
</TableRoot>
</theme:CustomTableView>
</ContentPage.Content>
</ContentPage>
using System;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using CoreGraphics;
using UIKit;
namespace Example.iOS.Renderers
{
public class CustomPageRenderer : PageRenderer
{
IPageController PageController => Element as IPageController;
StatusTabPage Parent => Element.Parent as StatusTabPage;
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e.NewElement is CustomPage)
{
((TabContentPage)e.NewElement).ShowPopup = this.ShowPopup;
}
}
// HACK: Store view controller because recreating causes issues.
UIViewController popoverContent;
void ShowPopup(Xamarin.Forms.View view, Xamarin.Forms.Page page)
{
if (popoverContent == null)
{
popoverContent = page.CreateViewController();
}
//var uiview = view.ToiOS();
//popoverController.PresentFromRect(uiview.Bounds, uiview, UIPopoverArrowDirection.Any, true);
popoverContent.ModalPresentationStyle = UIModalPresentationStyle.Popover;
var popover = popoverContent.PopoverPresentationController;
popoverContent.PreferredContentSize = new CGSize(300, 300);
popover.Delegate = popoverDelegate;
popover.SourceView = this.View;
popover.SourceRect = view.Bounds.ToRectangleF();
this.PresentViewController(popoverContent, true, null);
}
private static UIPopoverPresentationControllerDelegate popoverDelegate = new PopoverMenu();
public class PopoverMenu: UIPopoverPresentationControllerDelegate {
public override UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController forPresentationController)
{
return UIModalPresentationStyle.None;
}
public override UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController controller, UITraitCollection traitCollection)
{
return GetAdaptivePresentationStyle(controller);
}
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
xmlns:cells="clr-namespace:Example.Controls.Cells"
xmlns:theme="clr-namespace:Example.Controls.Theme"
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:controls="clr-namespace:SegmentedControl.FormsPlugin.Abstractions;assembly=SegmentedControl.FormsPlugin.Abstractions"
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific"
x:Class="Example.Views.PopupSettingsPage"
Title="Attachments" BackgroundColor="{StaticResource DarkBackgroundColor}">
<ContentPage.Content>
<theme:CustomTableView Intent="Settings" BackgroundColor="{StaticResource DarkBackgroundColor}">
<TableRoot>
<TableSection Title="Units">
<cells:SegmentedControlCell Label="Length">
<cells:SegmentedControlCell.Children>
<controls:SegmentedControlOption Text="feet" />
<controls:SegmentedControlOption Text="meters" />
</cells:SegmentedControlCell.Children>
</cells:SegmentedControlCell>
</TableSection>
</TableRoot>
</theme:CustomTableView>
</ContentPage.Content>
</ContentPage>
<?xml version="1.0" encoding="UTF-8"?>
<custom:ToolbarPage
xmlns:cells="clr-namespace:Example.Controls.Cells"
xmlns:theme="clr-namespace:Example.Controls.Theme"
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:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific"
x:Class="Example.Views.SettingsPage" BackgroundColor="{StaticResource DarkBackgroundColor}">
<ContentPage.Content>
<theme:CustomTableView Intent="Settings" BackgroundColor="{StaticResource DarkBackgroundColor}">
<TableRoot>
<TableSection Title="Reports">
<cells:NavigationCell Text="Attachments" Command="{Binding NavigateCommand}" CommandParameter="AttachmentsPage">
<ImageCell.ImageSource>
<OnPlatform x:TypeArguments="ImageSource"
Android="ic_attach_file_white_24dp.xml"
iOS="ic_attach_file_white.png" />
</ImageCell.ImageSource>
</cells:NavigationCell>
</TableSection>
</TableRoot>
</theme:CustomTableView>
</ContentPage.Content>
</ContentPage>
using System;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
namespace Example.ViewModels
{
public class SettingsPageViewModel : BindableBase, INavigationAware
{
protected INavigationService _navigationService { get; }
public BaseViewModel(INavigationService navigationService)
{
_navigationService = navigationService;
NavigateCommand = new DelegateCommand<string>(OnNavigateCommandExecuted);
}
public BaseViewModel(INavigationService navigationService)
: this(navigationService)
{ }
public DelegateCommand<string> NavigateCommand { get; }
private async void OnNavigateCommandExecuted(string path)
{
if (path.StartsWith("Modal", StringComparison.Ordinal))
{
await _navigationService.NavigateAsync(path, useModalNavigation: true);
}
else
{
await _navigationService.NavigateAsync(path);
}
}
#region INavigationAware
public virtual void OnNavigatedFrom(NavigationParameters parameters) { }
public virtual void OnNavigatedTo(NavigationParameters parameters) { }
public virtual void OnNavigatingTo(NavigationParameters parameters) { }
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.