Ebook gratuito rilasciato da Charles Petzold riguardante lo sviluppo di applicazioni per la piattaforma Windows Phone 7.
Visualizzazione post con etichetta "wp7". Mostra tutti i post
Visualizzazione post con etichetta "wp7". Mostra tutti i post
domenica 1 dicembre 2013
domenica 8 settembre 2013
Implementare INotifyPropertyChanged
Di seguito viene illustrato come implementare l'interfaccia INotifyPropertyChanged per notificare che una proprietà è cambiata.
public class ViewModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string propertyName) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(propertyName)); } } private string miaProprieta; public string MiaProprieta { get { return miaProprieta; } set { if (miaProprieta != value) { miaProprieta = value; OnPropertyChanged("MiaProprieta"); } } } }
Etichette:
"c#",
"mvvm",
"propetychanged",
"silverlight",
"windowsphone",
"wp7",
"wpf"
lunedì 19 agosto 2013
[WP7] Abilitare/Disabilitare bottoni dell'ApplicationBar
Metodo esteso per abilitare/disabilitare tutti i bottoni dell'ApplicationBar:
public static class ApplicationBarUtility { public static void SetButtonState(this IApplicationBar app, bool state) { if (app == null) return; app.IsMenuEnabled = state; foreach (ApplicationBarIconButton btn in app.Buttons) { btn.IsEnabled = state; } } }
Etichette:
"applicationbar",
"c#",
"wp7"
martedì 6 agosto 2013
[WPF] Riavviare applicazione
Riavviare applicazione WPF
System.Windows.Forms.Application.Restart(); System.Windows.Application.Current.Shutdown();
domenica 4 agosto 2013
Coding4Fun Toolkit 2.0.7
Versione 2.0.7 di Coding4Fun Toolkit rilasciata
New/Adjustments
- SafeDispatcher.Run was added.
- IsTypeOf extension now will work with stuff other than UI controls
- Moved IsDesignMode to ApplicationSpace, will deprecate old reference next push
- Moved CheckBounds to a number of helper extension class, will deprecate old reference next push
- Added TimeSpan, Int, Double, Float extension helpers for CheckBounds, AlmostEquals
- Added Numbers.Min, Numbers.Max for wrappers to Linq query for non-array wrapped numbers.
- Deprecate the old nuget packages from Coding4Fun.Phone time frame, they should auto update now. I kept forgetting to hide them.
- ImageTile - now have bitmaps with a delay create and background create
- ApplicationSpace.RootFrame - direct reference to root frame of the application
Bug Fixes
- TimeSpanPicker - DialogTitle works again
- TimeSpanPicker - Max is now enforced for during initial set.
- ChatBubbleTextBox - Fixed margin error
- LockScreenPreview - text viewable in light theme
- MemoryCounter - DispatcherTImer wasn't being properly destroyed
- MemoryCounter - FrameNavigated getting called on leaving and reentering
- ImageTile - FrameNavigated getting called on leaving and reentering
- Designer Theme Change ObjectDisposedException bug fixed. Occurred when you flipped between Light and Dark theme
venerdì 2 agosto 2013
[WP7] Aggiungere/Aggiornare/Rimuovere LiveTile a Start
Esempio che spiega come aggiungere/rimuovere le LiveTile a Start.
NB: Per le due immagini (Background.png e BackBackground.png) settare la proprietà Operazione di compilazione come Contenuto
internal enum Operation { Add, Remove } public partial class MainPage : PhoneApplicationPage { private void LiveTile(Operation operation) { const string TITLE = "LiveTile"; ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("TuoParametro=" + TITLE)); switch (operation) { //Aggiungo/Aggiorno LiveTile case Operation.Add: StandardTileData liveTile = new StandardTileData { Title = TITLE, BackgroundImage = new Uri("Background.png", UriKind.RelativeOrAbsolute), BackBackgroundImage = new Uri("BackBackground.png", UriKind.RelativeOrAbsolute), Count = 0, BackTitle = "LiveTile 1.0", BackContent = "Esempio LiveTile", }; if (tile == null) { //LiveTile non esistente -> Aggiugno a start try { ShellTile.Create(new Uri("/MainoPage.xaml?TuoParametro=" + liveTile.Title, UriKind.Relative), liveTile); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { //LiveTile esistente -> Aggiorno tile.Update(liveTile); } break; //Rimuovo LiveTile case Operation.Remove: if (tile != null) { //LiveTile esistente -> Rimuovo try { tile.Delete(); MessageBox.Show("LiveTile rimossa correttamente"); } catch (Exception ex) { MessageBox.Show(ex.Message); ; } } break; } } public MainPage() { InitializeComponent(); } private void btnAggiungi_Click(object sender, RoutedEventArgs e) { LiveTile(Operation.Add); } private void btnRimuovi_Click(object sender, RoutedEventArgs e) { LiveTile(Operation.Remove); } } |
NB: Per le due immagini (Background.png e BackBackground.png) settare la proprietà Operazione di compilazione come Contenuto
Etichette:
"c#",
"live tile",
"wp7"
mercoledì 31 luglio 2013
[WP7] Path to BitmapImage
Codice per ottere una BitmapImage a partire da un path.
Il path dovrà essere così composto: <NomeProgetto>;component/Path/NomeImmage
public static BitmapImage ImageFromPath(string path) { Uri imgUri = new Uri(path, UriKind.Relative); StreamResourceInfo imageResource = Application.GetResourceStream(imgUri); BitmapImage image = new BitmapImage(); image.SetSource(imageResource.Stream); return image; } |
Il path dovrà essere così composto: <NomeProgetto>;component/Path/NomeImmage
giovedì 25 luglio 2013
[WP7 - WP8] CarGest (Beta)
Vi segnalo un'app in versione beta: CarGest (per gestire tutte, o quasi, le spese delle vostre auto).
Link allo store
Funzionalità:
- Anagrafiche: Tipi rifornimento, Veicoli, Categorie manutenzione, Categorie uscita
- Rifornimenti
- Manutenzioni
- Uscite
- Backup/Restore tramite SkyDrive
Link allo store
Mandate una mail a ken_1986@hotmail.it per essere abilitati al download
venerdì 19 luglio 2013
[WP7] Leggere coordinate GPS
Leggere le coordinate GPS da un dispositivo Windows Phone 7.
using (var watcher = new GeoCoordinateWatcher()) { if (watcher.Permission == GeoPositionPermission.Granted) { watcher.TryStart(false, TimeSpan.FromSeconds(2)); if (!watcher.Position.Location.IsUnknown) { latitudine = watcher.Position.Location.Latitude; longitudine = watcher.Position.Location.Longitude; } watcher.Stop(); } else { MessageBox.Show("Non si dispone dei permessi"); } }
venerdì 21 giugno 2013
[WP7] UpdateSourceTrigger = PropertyChanged TextBox
WP7 essendo basato sul Silverlight 3 non supporta nativamente UpdateSourceTrigger = PropertyChanged. Per ovviare a ciò non ci resta che creare una classe ad hoc di supporto: BindingUtility.
L'utilizzo della classe è veramente semplice:
public class BindingUtility { public static bool GetUpdateSourceOnChange(DependencyObject d) { return (bool)d.GetValue(UpdateSourceOnChangeProperty); } public static void SetUpdateSourceOnChange(DependencyObject d, bool value) { d.SetValue(UpdateSourceOnChangeProperty, value); } public static readonly DependencyProperty UpdateSourceOnChangeProperty = DependencyProperty.RegisterAttached( "UpdateSourceOnChange", typeof(bool), typeof(BindingUtility), new PropertyMetadata(false, OnPropertyChanged)); private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var textBox = d as TextBox; if (textBox == null) return; if ((bool)e.NewValue) { textBox.TextChanged += OnTextChanged; } else { textBox.TextChanged -= OnTextChanged; } } static void OnTextChanged(object s, TextChangedEventArgs e) { UpdatePropertyChangedTextBox(s as TextBox); } public static void UpdatePropertyChangedTextBox(TextBox textBox) { if (textBox == null) return; var bindingExpression = textBox.GetBindingExpression(TextBox.TextProperty); if (bindingExpression != null) { bindingExpression.UpdateSource(); } } } |
L'utilizzo della classe è veramente semplice:
xmlns:utility="clr-namespace:XXX.Utility" <TextBox Text="{Binding TuaProprieta,Mode=TwoWay}" utility:BindingUtility.UpdateSourceOnChange="True"/> |
[WP7] Ottenere l'ApplicationBar globale
public static IApplicationBar GetGlobalAppBar() { return (IApplicationBar)Application.Current.Resources["GlobalApplicationBar"]; } |
Etichette:
"applicationbar",
"wp7"
[WP7] Grafico senza legenda
Rimuovere la legenda da un grafico (DataVisualization.Charting).
<Style x:Key="NoLegendStyle" TargetType="dataVis:Legend"> <Setter Property="Width" Value="0"/> <Setter Property="Height" Value="0"/> </Style>
N.B.: dataVis indica il seguente namespace:
xmlns:dataVis="clr-namespace:System.Windows.Controls.DataVisualization;
assembly=System.Windows.Controls.DataVisualization.Toolkit"
martedì 18 giugno 2013
[WPF/SL/WP] Clonare ObservableCollection
Metodo esteso che consente di clonare una generica ObservableCollection.
public static ObservableCollection<T> Clone<T> (this ObservableCollection<T> source) { if (source != null) { var res = new ObservableCollection<T>(); foreach (var item in source) { res.Add(Clone<T>(item)); } return res; } return null; } |
[WP7] Array byte to BitmapImage
Codice per convertire un array di byte in bitmapimage.
public static BitmapImage ImageFromBuffer(byte[] bytes) { var stream = new MemoryStream(bytes); { var image = new BitmapImage(); image.SetSource(stream); return image; } }
Iscriviti a:
Post (Atom)