Created
March 4, 2015 17:04
-
-
Save choipd/e2956024caec8a30bf2e to your computer and use it in GitHub Desktop.
NulReferenceException on XLabs.Forms.Controls.CheckBoxRenderer.OnElementChanged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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="PixbeeProto.NewAlbumPage" | |
Title="Create Album" | |
Padding="10, 40, 10, 10" | |
xmlns:controls="clr-namespace:XLabs.Forms.Controls;assembly=XLabs.Forms"> | |
<StackLayout> | |
<Label Text="Create a new album!" | |
VerticalOptions="Start" | |
XAlign="Center" | |
IsVisible="true" | |
FontSize="Large" | |
FontAttributes="Bold" | |
TextColor="Gray" /> | |
<StackLayout Orientation="Horizontal"> | |
<Label Text="Title"/> | |
<Entry WidthRequest = "200" | |
Text="Great Moment" x:Name="Title" /> | |
</StackLayout> | |
<StackLayout Orientation="Horizontal"> | |
<ListView x:Name="ListView"> | |
<ListView.ItemTemplate> | |
<DataTemplate> | |
<ViewCell> | |
<ViewCell.View> | |
<controls:CheckBox DefaultText="{Binding}" CheckedText="{Binding}" UncheckedText="{Binding}" HorizontalOptions="FillAndExpand" PropertyChanged="OnCheckedPropertyChanged" /> | |
</ViewCell.View> | |
</ViewCell> | |
</DataTemplate> | |
</ListView.ItemTemplate> | |
</ListView> | |
</StackLayout> | |
<StackLayout Orientation="Horizontal" HorizontalOptions="Center" VerticalOptions="Center"> | |
<Button Text="Create!" | |
Clicked="OnButtonClicked" /> | |
<BoxView Color="Transparent" WidthRequest="20" /> | |
<Button Text="Cancel" | |
Clicked="OnButtonClicked" x:Name="cancelButton" /> | |
</StackLayout> | |
<StackLayout> | |
<Label Text="Status" | |
x:Name="statusLabel" | |
Font="Small" | |
HorizontalOptions="Center" | |
VerticalOptions="CenterAndExpand" | |
/> | |
</StackLayout> | |
</StackLayout> | |
</ContentPage> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
using Xamarin.Forms; | |
using RestSharp.Portable; | |
using System.Net.Http; | |
using System.Linq; | |
namespace PixbeeProto | |
{ | |
public partial class NewAlbumPage : ContentPage | |
{ | |
public List<User> members = new List<User>(); | |
public NewAlbumPage () | |
{ | |
InitializeComponent (); | |
ListView.ItemsSource = Enum.GetValues(typeof(DayOfWeek)).OfType<DayOfWeek>().Select(c => c.ToString()); | |
} | |
void OnCheckedPropertyChanged(object sender, EventArgs args) | |
{ | |
Console.WriteLine ("checked {0}", args); | |
} | |
async void OnButtonClicked(object sender, EventArgs args) | |
{ | |
if (sender == cancelButton) { | |
await Navigation.PopModalAsync (); | |
return; | |
} | |
statusLabel.Text = "Creating..."; | |
List<string> memberIds = new List<string>(); | |
foreach (var member in this.members) { | |
memberIds.Add (member.Id); | |
} | |
Album album = await CreateAlbum (Title.Text, memberIds); | |
statusLabel.Text = string.Format ("{0} created.", album.Title); | |
await Navigation.PopModalAsync (); | |
} | |
private static async Task<Album> CreateAlbum(string title, List<string> memberIds) { | |
var client = new RestClient(new Uri(String.Format("{0}/api/", UserSession.Instnace.host))); | |
var request = new RestRequest ("albums", HttpMethod.Post); | |
request.AddHeader ("Authorization", String.Format ("Bearer {0}", UserSession.Instnace.token)); | |
request.AddQueryParameter ("album[title]", title); | |
foreach (var idString in memberIds) { | |
request.AddQueryParameter ("album[members]", idString); | |
} | |
var result = await client.Execute<Album> (request); | |
return result.Data; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment