Permalink
Browse files

Windows Phone tweaks

  • Loading branch information...
1 parent f712357 commit 1c3405a3c29c6d408e97718d14ea6b8ad0d192b7 @Redth committed Nov 28, 2012
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using System.Collections.ObjectModel;
using System.Threading.Tasks;
using System.Windows.Input;
using Cirrious.MvvmCross.Commands;
@@ -9,7 +10,7 @@ namespace WshLst.Core.ViewModels
public class WishListViewModel : BaseViewModel
{
public string ListId = string.Empty;
- private List<Entry> _entries;
+ private ObservableCollection<Entry> _entries;
private WishList _wishList;
@@ -28,7 +29,7 @@ public WishList WishList
}
}
- public List<Entry> Entries
+ public ObservableCollection<Entry> Entries
{
get { return _entries; }
set
@@ -82,17 +83,25 @@ public void Delete(Entry entry)
{
IsLoading = true;
+ var entryId = entry.Id;
+
App.Azure.GetTable<Entry>().DeleteAsync(entry).ContinueWith(t =>
{
var ex = t.Exception;
IsLoading = false;
- if (t.Status == TaskStatus.RanToCompletion)
- {
- _entries.Remove(entry);
- RaisePropertyChanged("Entries");
- }
+ this.InvokeOnMainThread(() =>
+ {
+ if (t.Status == TaskStatus.RanToCompletion)
+ {
+ if (_entries == null)
+ return;
+
+ _entries.Remove(entry);
+ RaisePropertyChanged("Entries");
+ }
+ });
});
}
@@ -127,16 +136,25 @@ public void LoadItems()
IsLoading = false;
- if (t.Status == TaskStatus.RanToCompletion)
- {
- _entries = new List<Entry>();
- _entries.AddRange(t.Result);
- RaisePropertyChanged("Entries");
- }
- else
- {
- ReportError("Failed to load items from WishList!");
- }
+ InvokeOnMainThread(() =>
+ {
+ if (t.Status == TaskStatus.RanToCompletion)
+ {
+ if (_entries == null)
+ _entries = new ObservableCollection<Entry>();
+
+ _entries.Clear();
+
+ foreach (var e in t.Result)
+ _entries.Add(e);
+
+ RaisePropertyChanged("Entries");
+ }
+ else
+ {
+ ReportError("Failed to load items from WishList!");
+ }
+ });
});
}
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.ObjectModel;
using System.Threading.Tasks;
using System.Windows.Input;
using Cirrious.MvvmCross.Commands;
@@ -10,14 +10,14 @@ namespace WshLst.Core.ViewModels
{
public class WishListsViewModel : BaseViewModel
{
- private List<WishList> _lists;
+ private ObservableCollection<WishList> _lists;
public WishListsViewModel()
{
LoadLists();
}
- public List<WishList> Lists
+ public ObservableCollection<WishList> Lists
{
get { return _lists; }
set
@@ -78,8 +78,9 @@ public void Delete(WishList item)
}
else
{
- _lists.Remove(item);
- RaisePropertyChanged(() => Lists);
+ this.InvokeOnMainThread(() => _lists.Remove(item));
+
+ RaisePropertyChanged("Lists");
}
});
}
@@ -95,14 +96,22 @@ public void LoadLists()
{
var ex = t.Exception;
- if (t.Status == TaskStatus.RanToCompletion)
- {
- _lists = new List<WishList>();
- _lists.AddRange(t.Result);
- RaisePropertyChanged(() => Lists);
- }
- else
- _lists = new List<WishList>();
+ this.InvokeOnMainThread(() =>
+ {
+ if (_lists == null)
+ _lists = new ObservableCollection<WishList>();
+
+ _lists.Clear();
+
+ if (t.Status == TaskStatus.RanToCompletion)
+ {
+ foreach (var wl in t.Result)
+ _lists.Add(wl);
+
+ RaisePropertyChanged(() => Lists);
+ }
+
+ });
IsLoading = false;
});
@@ -1,26 +1,18 @@
-using System;
-using System.Diagnostics;
-using System.Resources;
+using System.Diagnostics;
using System.Windows;
-using System.Windows.Markup;
using System.Windows.Navigation;
-using Microsoft.Phone.Controls;
-using Microsoft.Phone.Shell;
-using WshLst.Resources;
using Cirrious.MvvmCross.ExtensionMethods;
using Cirrious.MvvmCross.Interfaces.ServiceProvider;
using Cirrious.MvvmCross.Interfaces.ViewModels;
+using Microsoft.Phone.Controls;
+using Microsoft.Phone.Shell;
using WshLst.Core.Interfaces;
namespace WshLst
{
public partial class App : Application, IMvxServiceConsumer<IMvxStartNavigation>, IMvxServiceConsumer<IErrorSource>
{
- /// <summary>
- /// Provides easy access to the root frame of the Phone Application.
- /// </summary>
- /// <returns>The root frame of the Phone Application.</returns>
- public static PhoneApplicationFrame RootFrame { get; private set; }
+ private bool _onceOnlyNavigation;
/// <summary>
/// Constructor for the Application object.
@@ -43,19 +35,8 @@ public App()
if (Debugger.IsAttached)
{
// Display the current frame rate counters.
- Application.Current.Host.Settings.EnableFrameRateCounter = true;
-
- // Show the areas of the app that are being redrawn in each frame.
- //Application.Current.Host.Settings.EnableRedrawRegions = true;
+ Current.Host.Settings.EnableFrameRateCounter = true;
- // Enable non-production analysis visualization mode,
- // which shows areas of a page that are handed off to GPU with a colored overlay.
- //Application.Current.Host.Settings.EnableCacheVisualization = true;
-
- // Prevent the screen from turning off while under the debugger by disabling
- // the application's idle detection.
- // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
- // and consume battery power when the user is not using the phone.
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
}
@@ -64,47 +45,41 @@ public App()
var errorSource = this.GetService<IErrorSource>();
- errorSource.ErrorReported += (s2, e2) =>
- {
- MessageBox.Show(e2.Message, "Error", MessageBoxButton.OK);
- };
-
+ errorSource.ErrorReported += (s2, e2) => MessageBox.Show(e2.Message, "Error", MessageBoxButton.OK);
}
- private bool _onceOnlyNavigation = false;
+ /// <summary>
+ /// Provides easy access to the root frame of the Phone Application.
+ /// </summary>
+ /// <returns>The root frame of the Phone Application.</returns>
+ public static PhoneApplicationFrame RootFrame { get; private set; }
// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
- System.Diagnostics.Debug.WriteLine("Application_Launching");
+ Debug.WriteLine("Application_Launching");
RootFrame.Navigating += (navigatingSender, navigatingArgs) =>
- {
- if (_onceOnlyNavigation)
- return;
-
- navigatingArgs.Cancel = true;
- _onceOnlyNavigation = true;
- var applicationStart = this.GetService<IMvxStartNavigation>();
- RootFrame.Dispatcher.BeginInvoke(applicationStart.Start);
- };
+ {
+ if (_onceOnlyNavigation)
+ return;
+
+ navigatingArgs.Cancel = true;
+ _onceOnlyNavigation = true;
+ var applicationStart = this.GetService<IMvxStartNavigation>();
+ RootFrame.Dispatcher.BeginInvoke(applicationStart.Start);
+ };
}
- // Code to execute when the application is activated (brought to foreground)
- // This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
}
- // Code to execute when the application is deactivated (sent to background)
- // This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
}
- // Code to execute when the application is closing (eg, user hit Back)
- // This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{
}
@@ -132,7 +107,7 @@ private void Application_UnhandledException(object sender, ApplicationUnhandledE
#region Phone application initialization
// Avoid double-initialization
- private bool phoneApplicationInitialized = false;
+ private bool phoneApplicationInitialized;
// Do not add any additional code to this method
private void InitializePhoneApplication()
@@ -191,61 +166,5 @@ private void ClearBackStackAfterReset(object sender, NavigationEventArgs e)
}
#endregion
-
- // Initialize the app's font and flow direction as defined in its localized resource strings.
- //
- // To ensure that the font of your application is aligned with its supported languages and that the
- // FlowDirection for each of those languages follows its traditional direction, ResourceLanguage
- // and ResourceFlowDirection should be initialized in each resx file to match these values with that
- // file's culture. For example:
- //
- // AppResources.es-ES.resx
- // ResourceLanguage's value should be "es-ES"
- // ResourceFlowDirection's value should be "LeftToRight"
- //
- // AppResources.ar-SA.resx
- // ResourceLanguage's value should be "ar-SA"
- // ResourceFlowDirection's value should be "RightToLeft"
- //
- // For more info on localizing Windows Phone apps see http://go.microsoft.com/fwlink/?LinkId=262072.
- //
- private void InitializeLanguage()
- {
- try
- {
- // Set the font to match the display language defined by the
- // ResourceLanguage resource string for each supported language.
- //
- // Fall back to the font of the neutral language if the Display
- // language of the phone is not supported.
- //
- // If a compiler error is hit then ResourceLanguage is missing from
- // the resource file.
- RootFrame.Language = XmlLanguage.GetLanguage(AppResources.ResourceLanguage);
-
- // Set the FlowDirection of all elements under the root frame based
- // on the ResourceFlowDirection resource string for each
- // supported language.
- //
- // If a compiler error is hit then ResourceFlowDirection is missing from
- // the resource file.
- FlowDirection flow = (FlowDirection)Enum.Parse(typeof(FlowDirection), AppResources.ResourceFlowDirection);
- RootFrame.FlowDirection = flow;
- }
- catch
- {
- // If an exception is caught here it is most likely due to either
- // ResourceLangauge not being correctly set to a supported language
- // code or ResourceFlowDirection is set to a value other than LeftToRight
- // or RightToLeft.
-
- if (Debugger.IsAttached)
- {
- Debugger.Break();
- }
-
- throw;
- }
- }
}
}
@@ -54,6 +54,10 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
var photo = new BitmapImage();
byte[] bytes = System.Convert.FromBase64String((string) value);
+
+ if (bytes == null || bytes.Length <= 0)
+ return photo;
+
using (var stream = new MemoryStream(bytes))
{
photo.SetSource(stream);
@@ -1,3 +0,0 @@
-For the Windows Phone toolkit make sure that you have
-marked the icons in the "Toolkit.Content" folder as content. That way they
-can be used as the icons for the ApplicationBar control.
@@ -20,6 +20,7 @@
<phone:Pivot Title="WSH LST">
<!--Pivot item one-->
<phone:PivotItem Header="add item" Margin="10,-10,10,0">
+ <ScrollViewer>
<StackPanel Visibility="{Binding IsLoading, Converter={StaticResource InvertedVisibility}}">
<Button Click="scanBarcode_Click">scan barcode</Button>
<TextBlock>what is it called?</TextBlock>
@@ -43,10 +44,10 @@
<StackPanel Grid.Column="1">
<TextBlock>photo</TextBlock>
- <Image Name="photo" Source="{Binding EntryImage.Base64Image, Converter={StaticResource Base64Image}}" Visibility="{Binding HasPhoto, Converter={StaticResource Visibility}}" Width="160"></Image>
- <Button Name="buttonPhotoChoose" Click="choosePhoto_Click" Visibility="{Binding HasPhoto, Converter={StaticResource InvertedVisibility}}">choose photo</Button>
- <Button Name="buttonPhotoTake" Click="takePhoto_Click" Visibility="{Binding HasPhoto, Converter={StaticResource InvertedVisibility}}">take photo</Button>
- <Button Name="buttonRemPhoto" Click="removePhoto_Click" Visibility="{Binding HasPhoto, Converter={StaticResource Visibility}}">remove photo</Button>
+ <Image Name="photo" Source="{Binding EntryImage.ImageBase64, Converter={StaticResource Base64Image}}" Visibility="{Binding HasImage, Converter={StaticResource Visibility}}" Width="160"></Image>
+ <Button Name="buttonPhotoChoose" Click="choosePhoto_Click" Visibility="{Binding HasImage, Converter={StaticResource InvertedVisibility}}">choose photo</Button>
+ <Button Name="buttonPhotoTake" Click="takePhoto_Click" Visibility="{Binding HasImage, Converter={StaticResource InvertedVisibility}}">take photo</Button>
+ <Button Name="buttonRemPhoto" Click="removePhoto_Click" Visibility="{Binding HasImage, Converter={StaticResource Visibility}}">remove photo</Button>
</StackPanel>
</Grid>
@@ -55,6 +56,7 @@
<TextBox TextWrapping="Wrap" Height="120" Text="{Binding Entry.Notes, Mode=TwoWay, UpdateSourceTrigger=Explicit}" TextChanged="textbox_Changed"></TextBox>
</StackPanel>
+ </ScrollViewer>
</phone:PivotItem>
<!--Pivot item two-->
@@ -207,7 +207,6 @@
<Content Include="Assets\Tiles\IconicTileSmall.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
- <Content Include="README_FIRST.txt" />
<Content Include="Toolkit.Content\ApplicationBar.Cancel.png" />
<Content Include="Toolkit.Content\ApplicationBar.Check.png" />
<Content Include="Toolkit.Content\ApplicationBar.Delete.png" />

0 comments on commit 1c3405a

Please sign in to comment.