How i can find entry changed?
<Entry x:Name="one" Keyboard="Numeric" TextChanged="Entry_TextChanged" />
<Entry x:Name="two" Keyboard="Numeric" TextChanged="Entry_TextChanged" />
<Entry x:Name="tre" Keyboard="Numeric" TextChanged="Entry_TextChanged" />
private void Entry_TextChanged(object sender, TextChangedEventArgs e)
{
//which entry's value has changed (x:Name)
}
is there any way to find out?
Of course, but I want to find out which Entry was changed. one or two or three
You cannot access the x:Name property of a xaml element, because this is just a hint for the compiler to name the variable.
You can set the ClassId of your Entry so that you can retrieve it in the handler. Like this:
<Entry
x:Name="one"
ClassId="entry1"
Keyboard="Numeric"
TextChanged="Entry_TextChanged" />
<Entry
x:Name="two"
ClassId="entry2"
Keyboard="Numeric"
TextChanged="Entry_TextChanged" />
<Entry
x:Name="tre"
ClassId="entry3"
Keyboard="Numeric"
TextChanged="Entry_TextChanged" />
private void Entry_TextChanged(object sender, TextChangedEventArgs e)
{
var entry = (Entry)sender;
if(entry.ClassId==one.ClassId)
{
Console.WriteLine("you are in one entry");
}
else if(entry.ClassId==two.ClassId)
{
Console.WriteLine("you are in two entry");
}
else
{
Console.WriteLine("you are in three entry");
}
}
Check the sender!
private void Entry_TextChanged(object sender, TextChangedEventArgs e)
{
//which entry's value has changed (x:Name)
Entry theTextBox = (Entry)sender;
Console.WriteLine(theTextBox.Name) + " changed the value");
}
Related
In my Xamrin forms code i have configured MVVM light
RelayCommand is not hitting even though I have set the property in xaml page for the command.
XAML
<?xml version="1.0" encoding="utf-8"?><ContentPage BackgroundColor="White" xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ContractorActionSolution.CSA.CSAContentPages.Demo">
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness">
<OnPlatform.iOS>0,20,0,0</OnPlatform.iOS>
</OnPlatform>
</ContentPage.Padding>
<ContentPage.Content>
<StackLayout Padding="10" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Image x:Name="imgLogo" Source="sisystems_logo.jpg" HorizontalOptions="FillAndExpand" VerticalOptions="Start"/>
<StackLayout VerticalOptions="CenterAndExpand" Padding="20" HorizontalOptions="FillAndExpand">
<Label x:Name="lblmsg" TextColor="#F25B63" Text="Error Message"/>
<Entry x:Name="txtUserName" Placeholder="Email"/>
<Entry x:Name="txtPassword" Placeholder="Password" IsPassword="True"/>
<Button Command="{Binding IncrementCommand}" Text="Continue"/>
<Label Text="Can't Login ?" TextColor="#F25B63" HorizontalOptions="Center"/>
</StackLayout>
</StackLayout>
</ContentPage.Content>
Code
public partial class Demo : ContentPage
{
DemoViewModel _myViewModel;
public Demo ()
{
InitializeComponent ();
}
protected override void OnAppearing()
{
base.OnAppearing();
BindingContext = App.Locator.DemoVM;
_myViewModel = BindingContext as DemoViewModel;
}
protected override void OnDisappearing()
{
base.OnDisappearing();
_myViewModel.CleanUP();
}
}
Model
public class DemoViewModel : BaseViewModel
{
private string _name;
public string Name
{
get { return _name; }
set { Set(() => Name, ref _name, value); }
}
private RelayCommand _incrementCommand;
/// <summary>
/// Gets the IncrementCommand.
/// </summary>
public RelayCommand IncrementCommand
{
get
{
return _incrementCommand ?? (_incrementCommand = new RelayCommand(
() =>
{
}));
}
}
public void CleanUP()
{
Name = string.Empty;
}
}
I have also tried using RelayCommand and RelayAsyncCommand both are not working.
Property bindings are working fine,
I can add binding for entry with a string property, but not able to add RelayCommand with a button.
The problem might be the fact that the handler is empty and optimization actually omits it after compilation. Try to add anything inside, like Debug.WriteLine("Test"); to see if the breakpoint is hit then.
I'm new winphone. I have a issue with binding data.
I have a class weather with 2 properties Temp_C, and Temp_F. I want to bind temperature to a textblock.
I also have a switch to choose C and F.
How can I do to when I switch to C => text block binding Temp_C when I switch to F => text block binding Temp_F.
A solution could be to just have two text block and just toggle there visibility:
<TextBlock Text="{Binding Temp_C}" Visibility="{Binding Checked,ElementName=temperatureTogled,Converter={StaticResource boolToVisibilityConverter}}"/>
<TextBlock Text="{Binding Temp_F}" Visibility="{Binding Checked,ElementName=temperatureTogled,Converter={StaticResource boolToNotVisibilityConverter}}"/>
<toolkit:ToggleSwitch x:Name="temperatureTogled" .. />
Or otherwise another solution is just to add a Temp property and a IsCelsus property in your viewModel, do the switch between the two value inside your Temp property and bind the Temp property:
public class CurrentCondition : INotifyPropertyChanged
{
private bool isC;
public bool IsC
{
get { return isC; }
set
{
if (isC != value)
{
isC = value;
this.RaisePropertyChanged("IsC");
this.RaisePropertyChanged("TempShow");
}
}
}
private string temp_C;
public string Temp_C
{
get { return temp_C; }
set
{
if (temp_C != value)
{
temp_C = value;
this.RaisePropertyChanged("Temp_C");
this.RaisePropertyChanged("TempShow");
}
}
}
private string temp_F;
public string Temp_F
{
get { return temp_F; }
set
{
if (temp_F != value)
{
temp_F = value;
this.RaisePropertyChanged("Temp_F");
this.RaisePropertyChanged("TempShow");
}
}
}
private string tempShow;
public string TempShow
{
get
{
if (this.isC == true)
{
return temp_C + "°C";
}
else
{
return temp_F + "°F";
}
return tempShow;
}
}
}
<TextBlock Text="{Binding TempShow}"/>
<toolkit:ToggleSwitch x:Name="temperatureTogled" Checked="{Binding IsC,Mode=TwoWay}" />
Xaml
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock TextAlignment="Center" FontSize="{StaticResource PhoneFontSizeExtraExtraLarge}" Grid.ColumnSpan="2" Grid.Row="0" x:Name="txtTemperature" />
<RadioButton Checked="CentTempChecked" GroupName="Temperature" Grid.Column="0" Grid.Row="1" Content="C" />
<RadioButton Checked="FarTempChecked" GroupName="Temperature" Grid.Column="1" Grid.Row="1" Content="F" />
</Grid>
Code Behind
using System.Globalization;
public partial class MainPage : PhoneApplicationPage
{
private TemperatureUnitType temperatureUnitType = TemperatureUnitType.Celsius;
public MainPage()
{
InitializeComponent();
BindTemperature();
}
private void CentTempChecked(object sender, RoutedEventArgs e)
{
this.temperatureUnitType = TemperatureUnitType.Celsius;
BindTemperature();
}
private void FarTempChecked(object sender, RoutedEventArgs e)
{
this.temperatureUnitType = TemperatureUnitType.Fahrenheit;
BindTemperature();
}
private void BindTemperature()
{
var temperature = new Temperature();
txtTemperature.Text =
this.temperatureUnitType == TemperatureUnitType.Celsius ?
temperature.Celsius.ToString(CultureInfo.InvariantCulture) : temperature.Fahrenheit.ToString(CultureInfo.InvariantCulture);
}
}
public enum TemperatureUnitType
{
Celsius = 0,
Fahrenheit = 1,
}
public class Temperature
{
public double Celsius { get { return 45.3d; } }
public double Fahrenheit { get { return 96.3d; } }
}
In a publication app, you should probably use the toggle control present in the WP toolkit. You should also be persisting the temperature preference in the IsolatedStorage DB.
This is the code I have in my custom UserControl:
generic.xaml:
<UserControl x:Class="SoundControl.SoundClass"
x:Name="Uc"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Stretch">
<Grid x:Name="mygrid"
Background="Transparent"
Width="Auto">
<Grid.RowDefinitions>
<RowDefinition Height="70*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="350*" />
<ColumnDefinition Width="70*" />
</Grid.ColumnDefinitions>
<Button x:Name="SoundButton"
Content="{Binding MyName, ElementName=Uc}"
Grid.Column="0"
Grid.Row="0"
Click="RingtoneButton_Click" />
<Button x:Name="RingtoneButton"
Grid.Column="1"
Grid.Row="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Click="RingtoneButton_Click">
<Image Source="/Images/note.png"
Stretch="Fill"
Height="30"
Width="30" />
</Button>
<MediaElement x:Name="SoundContainer"
Source="{Binding MySound, ElementName=Uc}"
AutoPlay="False" />
</Grid>
</StackPanel>
</UserControl>
SoundControl.cs
namespace SoundControl
{
public partial class SoundClass : UserControl
{
SaveRingtoneTask saveRingtoneChooser;
public SoundClass()
{
// For ringtone
saveRingtoneChooser = new SaveRingtoneTask();
saveRingtoneChooser.Completed += new EventHandler<TaskEventArgs>(saveRingtoneChooser_Completed);
}
public static readonly DependencyProperty SoundSourceProperty =
DependencyProperty.Register("MySound", typeof(MediaElement), typeof(SoundClass), null);
public static readonly DependencyProperty SoundNameProperty =
DependencyProperty.Register("MyName", typeof(string), typeof(SoundClass), null);
public MediaElement MySound
{
get { return (MediaElement)this.GetValue(SoundSourceProperty); }
set { base.SetValue(SoundSourceProperty, value); }
}
public string MyName
{
get { return (string)this.GetValue(SoundNameProperty); }
set { base.SetValue(SoundNameProperty, value); }
}
public SoundClass()
{
InitializeComponent();
}
private void SoundButton_Click(object sender, RoutedEventArgs e)
{
SoundContainer.Play();
}
private void RingtoneButton_Click(object sender, RoutedEventArgs e)
{
saveRingtoneChooser.Source = new Uri(SoundContainer.Source.AbsoluteUri);
saveRingtoneChooser.DisplayName = MyName;
saveRingtoneChooser.Show();
}
void saveRingtoneChooser_Completed(object sender, TaskEventArgs e)
{
switch (e.TaskResult)
{
//Logic for when the ringtone was saved successfully
case TaskResult.OK:
MessageBox.Show("Ringtone saved.");
break;
//Logic for when the task was cancelled by the user
case TaskResult.Cancel:
MessageBox.Show("Save cancelled.");
break;
//Logic for when the ringtone could not be saved
case TaskResult.None:
MessageBox.Show("Ringtone could not be saved.");
break;
}
}
}
}
and my MainPage.xaml
<SoundControl:SoundClass
HorizontalAlignment="Left"
Grid.Row="0"
VerticalAlignment="Top"
Grid.ColumnSpan="2"
Width="456"
MyName="TEST123"
MySound="/project/test.mp3"
/>
The problem is the XAML in Mainpage. The MySound property is giving me the error
The TypeConverter for "MediaElement" does not support converting from a string.
Any help you can provide will be greatly appreciated!
The Source property of the MediaElement type takes a Uri, not another MediaElement object. Change the type of the dependency property MySound to Uri, not MediaElement. (Don't forget also to replace typeof(MediaElement) with typeof(Uri) within SoundSourceProperty.)
Incidentally, I'd also recommend renaming the two dependency property identifiers you have (SoundSourceProperty and SoundNameProperty) to MySoundProperty and MyNameProperty respectively. There is a convention that the name of the dependency property's identifier (i.e. the public static readonly field) is the name of the property that uses it (in your case MySound or MyName) followed by Property. Some tools will expect this convention to be followed.
I can get the list of Lat and Long in a list as a full string. I now need to be able to use this in the map.
Here is the code to display the map. Currently it's displaying two pins and the location. (xaml)
phone:PhoneApplicationPage
x:Class="BrightonHoveBuses.location"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="696" d:DesignWidth="480"
shell:SystemTray.IsVisible="True" xmlns:my="clr-
namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps">
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="PinItemTemplate">
<my:Pushpin Location="{Binding Location}"
MouseLeftButtonUp="Pushpin_MouseLeftButtonUp_1"
Content="{Binding Id}">
</my:Pushpin>
</DataTemplate>
<ControlTemplate x:Key="pinMyLoc"
TargetType="my:Pushpin">
<Grid Height="26"
Width="26"
Margin="-13,-13,0,0"
RenderTransformOrigin="0.5,0.5">
<Grid.RenderTransform>
<CompositeTransform Rotation="-45" />
</Grid.RenderTransform>
<Rectangle Fill="Black"
HorizontalAlignment="Center" Margin="0" Stroke="White" VerticalAlignment="Center" Height="26" Width="26" />
<Ellipse HorizontalAlignment="Center"
Height="16" Margin="0" VerticalAlignment="Center"
Fill="Teal"
Width="16" />
</Grid>
</ControlTemplate>
<DataTemplate x:Key="BusItemTemplate">
<my:Pushpin Location="{Binding Location}"
Name="{Binding Id}"
MouseLeftButtonUp="Pushpin_MouseLeftButtonUp_1">
<Grid>
<StackPanel Orientation="Horizontal">
<Image Source="/Images/1.png" Stretch="None" Width="20" Height="25"/>
</StackPanel>
</Grid>
</my:Pushpin>
</DataTemplate>
<ControlTemplate x:Key="stops"
TargetType="my:Pushpin">
<Grid Height="26"
Width="26"
Margin="-13,-13,0,0"
RenderTransformOrigin="0.5,0.5">
<Grid.RenderTransform>
<CompositeTransform Rotation="-45" />
</Grid.RenderTransform>
<Rectangle Fill="Black"
HorizontalAlignment="Center" Margin="0" Stroke="White" VerticalAlignment="Center" Height="26" Width="26" />
<Ellipse HorizontalAlignment="Center"
Height="16" Margin="0" VerticalAlignment="Center"
Fill="Yellow"
Width="16" />
</Grid>
</ControlTemplate>
</phone:PhoneApplicationPage.Resources>
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="BRIGHTON & HOVE BUSES" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="Stop Map" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<!-- This is the coding for the pushpins on the map-->
<Grid Grid.RowSpan="2">
<my:Map Name="map1" CredentialsProvider="Apg4fepCyTYEAQ0UxPKpbIljr_THidmUi7BNRth0JGtGSE0blId5FJSJqYy80kQC" Center="47.620574,-122.34942" Margin="0,139,6,99" Height="458" ZoomLevel="17" LogoVisibility="Visible" CopyrightVisibility="Visible" Loaded="startLocationButton_Click">
<my:Pushpin Location="{Binding CurrentLocation}" Template="{StaticResource pinMyLoc}" Name="myPushPin"/>
<my:MapItemsControl x:Name="MapPins"
ItemsSource="{Binding Pins}"
ItemTemplate="{StaticResource PinItemTemplate}"
/>
</my:Map>
<ListBox Height="87" HorizontalAlignment="Left" Margin="12,603,0,0" Name="listBox1" VerticalAlignment="Top" Width="460" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding latitude}"/>
<TextBlock Text="{Binding NaptanCode}"/>
<TextBlock Text=" "/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar Opacity="1.0" IsMenuEnabled="True" IsVisible="True">
<shell:ApplicationBarIconButton Text="Zoom In" IconUri="/Images/add.png" Click="Buttonplus_Click" />
<shell:ApplicationBarIconButton Text="Zoom Out" IconUri="/Images/minus.png" Click="Buttonminus_Click" />
<shell:ApplicationBarIconButton Text="Me" IconUri="/Images/location.png" Click="ButtonLocation_Click" />
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="Road View" Click="ApplicationBarRoad_Click" />
<shell:ApplicationBarMenuItem Text="Aerial View" Click="ApplicationBarAerial_Click" />
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
</phone:PhoneApplicationPage>
Heres the code....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Device.Location;
using Microsoft.Phone.Shell;
using System.Xml.Serialization;
using System.Xml;
using System.IO.IsolatedStorage;
using Microsoft.Phone.Controls;
using System.Runtime.Serialization.Json;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using System.Text;
using System.Xml.Linq;
using System.Data.Linq.Mapping;
using System.ComponentModel;
using Microsoft.Phone.Controls.Maps;
using Microsoft.Phone.Controls.Maps.Platform;
namespace BrightonHoveBuses
{
public partial class location : PhoneApplicationPage
{
public location()
{
InitializeComponent();
DataContext = App.ViewMapModel;
MapViewModel view = new MapViewModel();
view.Load();
this.DataContext = view;
WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
Uri url = new Uri("http://www.henry-edwards.co.uk/feed.txt", UriKind.Absolute);
client.DownloadStringAsync(url);
}
GeoCoordinateWatcher watcher;
// Click the event handler for the “Start Location” button.
private void startLocationButton_Click(object sender, RoutedEventArgs e)
{
// The watcher variable was previously declared as type GeoCoordinateWatcher.
if (watcher == null)
{
watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High); // using high accuracy
watcher.MovementThreshold = 20; // use MovementThreshold to ignore noise in the signal
watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
}
watcher.Start();
} // End of the Start button Click handler.
public class RootContainer
{
[DataMember]
public string StopName { get; set; }
[DataMember]
public string StopId { get; set; }
[DataMember]
public string Stop { get; set; }
[DataMember]
public string RouteId { get; set; }
[DataMember]
public string RouteName { get; set; }
[DataMember]
public string latitude { get; set; }
[DataMember]
public string longitude { get; set; }
[DataMember]
public List<Location> Location { get; set; }
}
void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
if ((App.Current as App).locsettings == false)
{
MessageBoxResult m = MessageBox.Show("Do you want to allow this application to use information about your location?", "Use Location", MessageBoxButton.OKCancel);
if (m == MessageBoxResult.OK)
{
watcher.Start();
(App.Current as App).locsettings = true;
}
else if (m == MessageBoxResult.Cancel)
{
watcher.Stop();
(App.Current as App).locsettings = false;
}
}
switch (e.Status)
{
case GeoPositionStatus.Disabled:
// The Location Service is disabled or unsupported.
// Check to see whether the user has disabled the Location Service.
if (watcher.Permission == GeoPositionPermission.Denied)
{
// The user has disabled the Location Service on their device.
MessageBox.Show("Location services must be enabled in your phone settings");
}
else
{
MessageBox.Show("Location services must be enabled");
}
break;
}
}
// Click the event handler for the “Start Location” button.
private void stopLocationButton_Click(object sender, RoutedEventArgs e)
{
watcher.Stop();
}
private GeoCoordinateWatcher loc = null;
public string stopslist;
private void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
myPushPin.Location = e.Position.Location;
map1.SetView(myPushPin.Location, 17.0);
watcher.MovementThreshold = 100;
}
void loc_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
if (e.Status == GeoPositionStatus.Ready)
{
map1.SetView(loc.Position.Location, 17.0);
loc.Stop();
}
}
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
if (e.Result != null)
{
XDocument doc = XDocument.Parse(e.Result);
XNamespace ns = "http://schemas.datacontract.org/2004/07/BusExpress.ClassLibrary";
var locations = (from n in doc.Descendants(ns + "ArrayOfStop")
select new RootContainer
{
Location = (from s in n.Elements(ns + "Stop")
select new Location
{
latitude = s.Element(ns + "Lat").Value + " ," + s.Element(ns + "Long").Value,
// longitude = s.Element(ns + "Long").Value,
}).ToList()
}).Single();
// Do something with the list of Route Names in routeNames
listBox1.ItemsSource = locations.Location;
}
}
}
public class MapViewModel : INotifyPropertyChanged
{
public void Load()
{
//Do something here to populate your view collection with pins
Pins.Add(new PinModel() { Id = 2, Name = string.Format("Pin # 2"), Location = new GeoCoordinate(39.932825, -75.168396) });
}
private ObservableCollection<PinModel> _pins = new ObservableCollection<PinModel>();
public ObservableCollection<PinModel> Pins
{
get { return _pins; }
set { _pins = value; RaisePropertyChanged("Pins"); }
}
//Event code to ensure the page updates to model changes.
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private void Pushpin_MouseLeftButtonUp_1(object sender, MouseButtonEventArgs e)
{
Pushpin pin = (Pushpin)sender;
MessageBox.Show(pin.Content.ToString());
}
public class PinModel
{
public string Name { get; set; }
public int Id { get; set; }
public GeoCoordinate Location { get; set; }
}
}
private void ButtonLocation_Click(object sender, EventArgs e)
{
loc = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
//EventHandler for location service status changes
loc.StatusChanged += loc_StatusChanged;
//If the location service is disabled or not supported
if (loc.Status == GeoPositionStatus.Disabled)
{
//Display a message
MessageBox.Show("Location services must be enabled");
return;
}
loc.Start();
}
private void Pushpin_MouseLeftButtonUp_1(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
Pushpin pin = (Pushpin)sender;
}
private void Buttonminus_Click(object sender, EventArgs e)
{
double zoom;
zoom = map1.ZoomLevel;
map1.ZoomLevel = --zoom;
}
private void Buttonplus_Click(object sender, EventArgs e)
{
double zoom;
zoom = map1.ZoomLevel;
map1.ZoomLevel = ++zoom;
}
private void ApplicationBarRoad_Click(object sender, EventArgs e)
{
map1.Mode = new RoadMode();
}
private void ApplicationBarAerial_Click(object sender, EventArgs e)
{
map1.Mode = new AerialMode();
}
}
}
EDIT:
public class PinModel : INotifyPropertyChanged
{
public string Name { get; set; }
public int Id { get; set; }
public GeoCoordinate Location { get; set; }
}
EDIT:
I am trying to get all the stops on a bing map. I can get all the locations in a list, this is populated to a list box. This all works.
It's now trying to get all these locations onto the map, also with names.
So i need to do whats on the website - but on the phone - http://www.buses.co.uk/travel/live-bus-times.aspx
Have you checked out the output of your LINQ method? It appears you are only creating one instance in your list. Try this instead of your current parsing method.
var locations = (from n in doc.Descendants(ns + "ArrayOfStop")
select new RootContainer
{
Location = (from s in n.Elements(ns + "Stop")
select new Location
{
latitude = s.Element(ns + "Lat").Value + " ," + s.Element(ns + "Long").Value,
// longitude = s.Element(ns + "Long").Value,
}).ToList()
});
I'm not pretty sure what your question is, but I think your binding with the pushpins is not working?
You have implemented INotifyPropertyChanged on your ObservableCollection. That's not necessary. To make it work, you have to implement it on the PinModel and when you set the Location property than call the RaisePropertyChanged method.
Your PinModel class should look something like below to make your binding work (Allthough it's possible that your binding is working right now, because you bind it once as a whole.)
public class PinModel : INotifyPropertyChanged
{
public string Name { get; set; }
public int Id { get; set; }
private GeoCoordinate _location;
public GeoCoordinate Location
{
get
{
return _location;
}
set
{
_location = value;
RaisePropertyChanged("Location");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Also note that het .Single() method your calling on your linq query is returning a single value instead of a list. Please have a look at the answer by Lance on how to contruct your linq query. (See this link for the .Single() documentation)
I am using two toggleSwitches as below from the WP7 control toolkit. Based on the first toggle, the second toggle switch should be enabled or disabled. The disable of the second toggle switch works fine but when the enable is performed, the text foreground is never changed. Please help me figure out why this is happening.
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<toolkit:ToggleSwitch Header="twitter" Margin="10,15,0,0" Name="toggleTwitter" Checked="toggleTwitter_Checked" Unchecked="toggleTwitter_Unchecked">
<toolkit:ToggleSwitch.HeaderTemplate>
<DataTemplate>
<ContentControl FontSize="{StaticResource PhoneFontSizeLarge}" Foreground="{StaticResource PhoneForegroundBrush}" Content="{Binding}"/>
</DataTemplate>
</toolkit:ToggleSwitch.HeaderTemplate>
<toolkit:ToggleSwitch.ContentTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Status: " FontSize="{StaticResource PhoneFontSizeMedium}"/>
<ContentControl HorizontalAlignment="Left" FontSize="{StaticResource PhoneFontSizeMedium}" Content="{Binding}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</toolkit:ToggleSwitch.ContentTemplate>
</toolkit:ToggleSwitch>
<toolkit:ToggleSwitch Header="" Margin="10,100,0,-35" Name="toggleTwitterAutoPublish" Checked="toggleTwitterAutoPublish_Checked" Unchecked="toggleTwitterAutoPublish_Unchecked">
<toolkit:ToggleSwitch.ContentTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Auto Publish: " FontSize="{StaticResource PhoneFontSizeMedium}" Margin="0,-15,0,0" />
<ContentControl HorizontalAlignment="Left" FontSize="{StaticResource PhoneFontSizeMedium}" Content="{Binding}" IsEnabled="{Binding}" Margin="0,-15,0,0"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</toolkit:ToggleSwitch.ContentTemplate>
</toolkit:ToggleSwitch>
</Grid>
public partial class MainPage : PhoneApplicationPage
{
bool isConnected = false;
bool isAutoPublish = false;
public const string SIGNED_IN_MESSAGE = "Signed In";
public const string SIGNED_OUT_MESSAGE = "Signed Out";
// Constructor
public MainPage()
{
InitializeComponent();
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
toggleTwitter.IsChecked = isConnected;
AlterTwitterControlsDisplay();
base.OnNavigatedTo(e);
}
#region Twitter
private void AlterTwitterControlsDisplay()
{
if (toggleTwitter.IsChecked.Value)
{
toggleTwitter.Content = SIGNED_IN_MESSAGE;
toggleTwitterAutoPublish.IsEnabled = true;
toggleTwitterAutoPublish.IsChecked = isAutoPublish;
}
else
{
toggleTwitter.Content = SIGNED_OUT_MESSAGE;
toggleTwitterAutoPublish.IsEnabled = false;
toggleTwitterAutoPublish.IsChecked = false;
}
}
private void toggleTwitter_Checked(object sender, RoutedEventArgs e)
{
isConnected = true;
AlterTwitterControlsDisplay();
}
private void toggleTwitter_Unchecked(object sender, RoutedEventArgs e)
{
isConnected = false;
AlterTwitterControlsDisplay();
}
private void toggleTwitterAutoPublish_Checked(object sender, RoutedEventArgs e)
{
isAutoPublish = true;
}
private void toggleTwitterAutoPublish_Unchecked(object sender, RoutedEventArgs e)
{
isAutoPublish = false;
}
#endregion Twitter
}
On doing
toggleTwitterAutoPublish.IsChecked = false;
(in AlterTwitterControlsDisplay function's else part), the toggleTwitterAutoPublish_Unchecked is triggered which sets isAutoPublish = false
hence next time when you try to do
toggleTwitterAutoPublish.IsChecked = isAutoPublish;
here isAutoPublish is false hence you may not get the desired result.
That is what I have understood from your question. If this was not the problem please explain it clearly. Hope this helps