I'm having trouble setting the rootpage of my Application. I wasn't able to show the right page. The first Mainpage is the default from the start and the second MainPage there is the name of the page that I created. Here's my code.
App.cs
public App()
{
MainPage = new NavigationPage(new MainPage());
}
And here is the code of my the page that i want to set as root page.
MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:XamarinDemoApp"
x:Class="XamarinDemoApp.MainPage"
xmlns:ViewModels="clr-namespace:XamarinDemoApp.ViewModels;assembly=XamarinDemoApp">
<ContentPage.BindingContext>
<ViewModels:MainViewModel />
</ContentPage.BindingContext>
<ListView ItemsSource="{Binding EmployeesList}"
HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding Name}"
FontSize="24"/>
<Label Text="{Binding Department}"
FontSize="18"
Opacity="0.6"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage>
This is the code behind my MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using XamarinDemoApp.ViewModels;
namespace XamarinDemoApp
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
}
}
}
This is the Stack Trace field I get.
[External Code]
> 0xC in XamarinDemoApp.MainPageMain.InitializeComponent at c:\Users\LIFEBOOK E743\Documents\Visual Studio 2013\Projects\XamarinDemoApp\XamarinDemoApp\obj\Debug\XamarinDemoApp.Views.MainPageMain.xaml.g.cs:21,13 C#
0x9 in XamarinDemoApp.MainPageMain..ctor at c:\Users\LIFEBOOK E743\Documents\Visual Studio 2013\Projects\XamarinDemoApp\XamarinDemoApp\Views\MainPageMain.xaml.cs:16,13 C#
0x9 in XamarinDemoApp.App..ctor at c:\Users\LIFEBOOK E743\Documents\Visual Studio 2013\Projects\XamarinDemoApp\XamarinDemoApp\App.cs:14,12 C#
0x12 in XamarinDemoApp.Droid.MainActivity.OnCreate at c:\Users\LIFEBOOK E743\Documents\Visual Studio 2013\Projects\XamarinDemoApp\XamarinDemoApp.Droid\MainActivity.cs:20,13 C#
0x13 in Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ at /Users/builder/data/lanes/3053/a94a03b5/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.App.Activity.cs:2857,4 C#
This is in the wrong place ...
NavigationPage.SetHasNavigationBar(this, false);
It should be
public App()
{
var mainPage = new NavigationPage(new MainPage());
NavigationPage.SetHasNavigationBar(this, false);
MainPage = mainPage;
}
Related
Please help me out. In order for you to understand my problem, I have replicated the scenario in sample application
As Xamarin.Forms introduced FlyoutPage page in 5.0 version, navigation is not working in one of the applications.
I am opening main page from app.xaml.cs like this await NavigationService.NavigateAsync("Page3");
FlyoutPage:
<FlyoutPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:PrismNavigation.Views;assembly=PrismNavigation"
xmlns:prism="http://prismlibrary.com"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="PrismNavigation.Views.Page3"
Title="Master">
<FlyoutPage.Flyout>
<ContentPage Title="Menu">
<StackLayout>
<Button Text="Page2" HeightRequest="50" WidthRequest="100" Command="{Binding NavigateCommand}" CommandParameter="Page2"></Button>
</StackLayout>
</ContentPage>
</FlyoutPage.Flyout>
<FlyoutPage.Detail>
<NavigationPage>
<x:Arguments>
<views:Page1></views:Page1>
</x:Arguments>
</NavigationPage>
</FlyoutPage.Detail>
</FlyoutPage>
Page3ViewModel:
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PrismNavigation.ViewModels
{
public class Page3ViewModel : ViewModelBase
{
private readonly INavigationService navigationService;
public Page3ViewModel(
INavigationService navigationService)
: base(navigationService)
{
this.navigationService = navigationService;
this.NavigateCommand = new DelegateCommand<string>(this.NavigateCommandExecute);
}
public override void OnNavigatedTo(INavigationParameters parameters)
{
base.OnNavigatedTo(parameters);
}
private void NavigateCommandExecute(string obj)
{
this.navigationService.NavigateAsync($"NavigationPage/{obj}");
}
public DelegateCommand<string> NavigateCommand { get; set; }
}
}
App:
using Prism;
using Prism.Ioc;
using PrismNavigation.ViewModels;
using PrismNavigation.Views;
using Xamarin.Essentials.Implementation;
using Xamarin.Essentials.Interfaces;
using Xamarin.Forms;
namespace PrismNavigation
{
public partial class App
{
public App(IPlatformInitializer initializer)
: base(initializer)
{
}
protected override async void OnInitialized()
{
InitializeComponent();
await NavigationService.NavigateAsync("Page3");
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterSingleton<IAppInfo, AppInfoImplementation>();
containerRegistry.RegisterForNavigation<NavigationPage>();
containerRegistry.RegisterForNavigation<Page1>();
containerRegistry.RegisterForNavigation<Page2>();
containerRegistry.RegisterForNavigation<Page3, Page3ViewModel>();
}
}
}
When I am trying to navigate to Page2 from menu, i can not do that. When I click the button, navigate command is executed, but navigation is not happening.
Update:
In addition to my old answer, which you have fixed in the question, it seems that the FlyoutPage is not supported by Prism 8 according to this. It is planned for 8.1. So, you can either wait 8.1 or replace it with MasterDetailPage. I tried your example with MasterDetailPage and it worked fine for me:
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="http://prismlibrary.com"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="PrismNavigation.Views.Page3">
<MasterDetailPage.Master>
<ContentPage Title="Menu">
<StackLayout Padding="20">
<Button Text="Page2" HeightRequest="50" WidthRequest="100" Command="{Binding NavigateCommand}" CommandParameter="Page2"></Button>
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<ContentPage Title="This is Page1"></ContentPage>
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
Old answer:
Seems like you didn't pass any parameter to your NavigateCommand. Try this
<StackLayout>
<Button Text="Page2" HeightRequest="50" WidthRequest="100" Command="{Binding NavigateCommand}" CommandParameter="Page2"></Button>
</StackLayout>
I work with an application made in Xamarin Forms that works on Android and IOS. I use a webview with a html and inside this html I call a javascript function when I login.
On Android it works fine but on IOS it doesn't work.
I read and apparently the error is due to the change from UIWebview to WKWebview, but so far I don't know how to fix this error.
I made my application on Windows in Visual Studio 2019, on the simulator device it works but on a physical device it doesn't work. In this case on Iphone not works.
This is my code:
LoginPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyLogin.Views.LoginPage">
<ContentPage.Content>
<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
<Label Text="Sign In" FontAttributes="Bold" FontSize="Title" HorizontalOptions="Center" VerticalOptions="Center" HeightRequest="50" />
<Entry x:Name="emailEntry"
Grid.Row="2"
BackgroundColor="#31FFFFFF"
Placeholder="Email"
PlaceholderColor="#3AAAF4" />
<Entry x:Name="passwordEntry"
Grid.Row="3"
Margin="0,0,0,0"
BackgroundColor="#31FFFFFF"
IsPassword="True"
Placeholder="Password"
PlaceholderColor="#3AAAF4" />
<Button Text="Login" Clicked="OnLoginButtonClicked" BackgroundColor="#3AAAF4" TextColor="White" CornerRadius="8" />
<Label></Label>
<Label x:Name="messageLabel" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" WidthRequest="50" TextColor="Black" FontAttributes="Bold" />
<WebView x:Name="webView" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" IsVisible="false" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
LoginPage.cs
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Plugin.DeviceInfo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using Microsoft.CSharp;
using System.Net;
using System.IO;
using System.Reflection;
using Xamarin.Essentials;
using System.Web;
namespace MyLogin.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class LoginPage : ContentPage
{
public string BlackboxString = "";
public LoginPage()
{
InitializeComponent();
webView.Source = LoadHTMLFileFromResource();
}
async void OnLoginButtonClicked(object sender, EventArgs e)
{
var blackbox = "";
blackbox = await webView.EvaluateJavaScriptAsync($"getBlackbox()");
//Code to login
}
private string GetLocalAddress()
{
var IpAddress = Dns.GetHostAddresses(Dns.GetHostName()).FirstOrDefault();
if (IpAddress != null)
return IpAddress.ToString();
return "Could not locate IP Address";
}
HtmlWebViewSource LoadHTMLFileFromResource()
{
var source = new HtmlWebViewSource();
// load HTML embed in PCL
var assembly = typeof(MainPage).GetTypeInfo().Assembly;
var stream = assembly.GetManifestResourceStream("mypage.mypagename.html");
using (var reader = new StreamReader(stream))
{
source.Html = reader.ReadToEnd();
}
return source;
}
}
}
Please help me,
Thanks
I cannot figure out how this is done. I have a page with a Collection view and Image inside of each cell.
I do also have a list of URLs, each one pointing to a jpg. What I would like to do is display each jpg in one of those cells.
<StackLayout Margin="20">
<CollectionView ItemsSource="{Binding UrlCollection}">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical"
Span="2" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Image Source="{Binding ImageUrl}"
Aspect="AspectFill" />
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
So far It looks to me that i have to make a class, called UrlCollection, and one item inside that class ist the ImageUrl. But i feel lost and cannot find a example to follow.
UPDATE My current version. its not working, the display is simply blank.
Gallery.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:vm="clr-namespace:GalShare.ViewModel"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="GalShare.Views.Gallery">
<ContentPage.BindingContext>
<vm:GalleryViewModel/>
</ContentPage.BindingContext>
<StackLayout>
<CollectionView ItemsSource="{Binding Gallery}">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical"
Span="2" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Image Source="{Binding ImageUrl}"
Aspect="AspectFit" />
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
Gallery.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace GalShare.Model
{
class Gallery
{
public string ImageName { get; set; }
public string ImageUrl { get; set; }
}
}
GalleryService.cs
using GalShare.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
namespace GalShare.Service
{
class GalleryService
{
public ObservableCollection<Gallery> GetImageList()
{
return new ObservableCollection<Gallery>()
{
new Gallery() { ImageName="Image1", ImageUrl="https://www.igormasin.it/fileuploads/tanja_23a6id/IMG_0992-Edit_a.jpg"},
new Gallery() { ImageName="Image2", ImageUrl="https://www.igormasin.it/fileuploads/tanja_23a6id/IMG_1024-Edit_a.jpg"},
new Gallery() { ImageName="Image3", ImageUrl="https://www.igormasin.it/fileuploads/tanja_23a6id/IMG_1074-Edit_a.jpg"}
};
}
}
}
GalleryViewModel.cs
using GalShare.Model;
using GalShare.Service;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
namespace GalShare.ViewModel
{
class GalleryViewModel
{
public ObservableCollection<Gallery> Images { get; set; }
public GalleryViewModel()
{
Images = new GalleryService().GetImageList();
}
}
}
Main page call:
MainPage = new NavigationPage(new Gallery());
First create a Model and ViewModel and populate a ViewModel property with a List of Model object.
public class ViewModel
{
public ObservableCollection<ImageData> UriCollection { get; set; }
public ViewModel()
{
UriCollection = new ObservableCollection<ImageData>();
for(var i=0; i<10; i++)
{
UriCollection.Add(new ImageData()
{
ImgeUri = "https://i.stack.imgur.com/di65V.jpg?s=328&g=1"
};
}
}
}
public class ImageData
{
public string ImgeUri { get; set; }
}
Set a ViewModel containing the UriCollection as BindingContext to the Page
MainPage.Xaml.cs
public MainPage()
{
InitializeComponent();
this.BindingContext = new ViewModel();
}
Usage in Xaml
<CollectionView ItemsSource="{Binding UriCollection}">
<CollectionView.ItemTemplate>
<DataTemplate>
<Image Aspect="AspectFit" Source="{Binding ImgeUri}" />
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Just check the image below. I want to change the color of marked areas on the Image. The image is a screenshot of UWP application developed using xamarin forms cross platform project (PCL).
I am using MasterDetail page navigation.
Now Color is changed as per my first requirement.
Now what I want is a screen design like below
Now I am getting a result as below
Result of second screen ie, after navigating to stock entry page
Source Code
1. MasterDetailsPage.Xaml
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="GST.Views.MasterDetailsPage"
Title="Stock Manager"
MasterBehavior="SplitOnPortrait"
BackgroundColor="#0063b1"
xmlns:pages="clr-namespace:GST.Views;assembly=GST">
<MasterDetailPage.Master >
<pages:MasterDetailsPageMaster x:Name="MasterPage" />
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage >
<x:Arguments>
<pages:GST_Home />
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
2. MasterDetailsPage.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace GST.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MasterDetailsPage : MasterDetailPage
{
public MasterDetailsPage()
{
InitializeComponent();
MasterPage.ListView.ItemSelected += ListView_ItemSelected;
}
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var item = e.SelectedItem as MasterDetailsPageMenuItem;
if (item == null)
return;
var page = (Page)Activator.CreateInstance(item.TargetType);
Detail.Title = item.Title;
IsPresented = false;
Detail.Navigation.PushAsync(page);
MasterPage.ListView.SelectedItem = null;
}
}
}
3. MasterDetailsPageDetail.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="GST.Views.MasterDetailsPageDetail"
BackgroundColor="{StaticResource Key=background-color}"
Title="Master GST Title Detailed" >
<StackLayout Padding="10">
<Label Text="This is a detail page. To get the 'triple' line icon on each platform add a icon to each platform and update the 'Master' page with an Icon that references it."/>
</StackLayout>
</ContentPage>
4.MasterDetailsPageDetail.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace GST.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MasterDetailsPageDetail : ContentPage
{
public MasterDetailsPageDetail()
{
InitializeComponent();
// NavigationPage.SetHasBackButton(this, false);
// NavigationPage.SetHasNavigationBar(this, false);
}
}
}
5. MasterDetailsPageMaster.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="GST.Views.MasterDetailsPageMaster"
Title="Home">
<StackLayout>
<ListView x:Name="ListViewMenuItems"
SeparatorVisibility="None"
HasUnevenRows="true"
ItemsSource="{Binding MenuItems}">
<ListView.Header>
<Grid BackgroundColor="#03A9F4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="10"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="80"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<Label
Grid.Column="1"
Grid.Row="2"
Text="AppName"
Style="{DynamicResource SubtitleStyle}"/>
</Grid>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="15,10" HorizontalOptions="FillAndExpand">
<Label VerticalOptions="FillAndExpand"
VerticalTextAlignment="Center"
Text="{Binding Title}"
FontSize="24"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
6.MasterDetailsPageMaster.cs
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace GST.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MasterDetailsPageMaster : ContentPage
{
public ListView ListView => ListViewMenuItems;
public MasterDetailsPageMaster()
{
InitializeComponent();
BindingContext = new ViewModels.MasterDetailsPageMasterViewModel();
}
}
}
7.MasterDetailsPageMenuItem.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GST.Views
{
public class MasterDetailsPageMenuItem
{
public MasterDetailsPageMenuItem()
{
TargetType = typeof(MasterDetailsPageDetail);
}
public int Id { get; set; }
public string Title { get; set; }
public Type TargetType { get; set; }
}
}
8.GST_Home.xaml -- Home Dash
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
NavigationPage.HasNavigationBar="False"
Title="Home Dash"
x:Class="GST.Views.GST_Home">
<StackLayout Padding="10">
<Label Text="This is a detail page. To get the 'triple' line icon on each platform add a icon to each platform and update the 'Master' page with an Icon that references it."/>
</StackLayout>
</ContentPage>
9.GST_Home.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace GST.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class GST_Home : ContentPage
{
public GST_Home()
{
InitializeComponent();
}
}
}
If you want full source code please refer my code which is uploaded on Google Drive: https://drive.google.com/file/d/0B2XtD2dQvEhzb1NnNGdydG91S0k/view?usp=sharing
If you wish to maintain the color of Title bar through out the app then you can write the following code inside the OnLaunched in the App.xaml.cs within Xamarin.UWP client project. For more please refer to Customizing Title Bar and Status Bar in Universal Windows Platform (UWP).
if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.ApplicationView"))
{
var titleBar = ApplicationView.GetForCurrentView().TitleBar;
if (titleBar != null)
{
titleBar.ButtonBackgroundColor = Colors.Red;
titleBar.ButtonForegroundColor = Colors.White;
titleBar.BackgroundColor = Colors.Red;
titleBar.ForegroundColor = Colors.White;
}
}
And if you want to custom tool bar background color, you could set the BarBackgroundColor of the NavigationPage. You can do something like the following code.
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
......
var nav = new NavigationPage();
nav.PushAsync(page);
nav.BarBackgroundColor = Color.MediumPurple;
Detail = nav;
}
I'm trying to load icons into a ImageCell inside a ListView, but when I build my project the icon doesn't appear on the ImageCell.
Here's my project structure:
Here's my XAML page:
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyNotes.StartPage">
<MasterDetailPage.Master Title="Menu">
<ContentPage Title="Menu">
<StackLayout VerticalOptions="FillAndExpand">
<ListView x:Name="listViewMaster" VerticalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ImageCell Text="{Binding Title}" ImageSource="{Binding IconSource}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<ContentPage>
</ContentPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
And here's the code behind:
using System.Collections.Generic;
using Xamarin.Forms;
namespace MyNotes
{
public partial class StartPage : MasterDetailPage
{
public StartPage ()
{
InitializeComponent ();
List<MasterPageItem> masterPageItems = new List<MasterPageItem>()
{
new MasterPageItem()
{
Title = "Contacts",
IconSource = ImageSource.FromFile(#"c:\Projetos\MyNotes\MyNotes\MyNotes\Resources\image\contacts.png"),
TargetType = typeof(ContactPage)
},
new MasterPageItem()
{
Title = "Todo List",
IconSource = ImageSource.FromFile(#"Resources\image\todo.png"),
TargetType = typeof(TodoListPage)
},
new MasterPageItem()
{
Title = "Reminder",
IconSource = ImageSource.FromResource("Resources.image.reminder.png"),
TargetType = typeof(ContactPage)
}
};
listViewMaster.ItemsSource = masterPageItems;
}
}
}
What am I doing wrong?
The images go into your "native" projects:
Xamarin.iOS = BundledResource Build Type
Xamarin.Android = AndroidResource Build Type
IconSource = ImageSource.FromFile("SanFran.jpg")
or using the implicit conversion:
IconSource = "SanFran.jpg";
Working with Images
Have you marked the images that you added to the project as embedded reousrces?
embedded resource