ProgressRing never shows - windows-phone-8.1

I have created a page, in which I have placed inside the Grid the above:
<ProgressRing x:Name="Ring" HorizontalAlignment="Center" VerticalAlignment="Center" IsEnabled="True"/>
But when I do Ring.IsActive = true; in my code nothing happens! Possibly I am missing something very simple here, but I can't find out what it is.
This is my xaml:
<Page
x:Class="Diakopes_v2._0.AddExpense"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Diakopes_v2._0"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Background="#FF0277BD">
<Page.BottomAppBar>
<CommandBar>
<AppBarButton Icon="Accept" Label="Accept" Click="Accept_Click"/>
<AppBarButton Icon="Cancel" Label="Cancel" Click="Cancel_Click"/>
</CommandBar>
</Page.BottomAppBar>
<Grid>
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF0277BD" Offset="0"/>
<GradientStop Color="#FFE1F5FE" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>
<TextBlock Text="New Expense" TextAlignment="Center" FontSize="46" FontFamily="/Assets/Fonts/BebasNeue Bold.ttf#Bebas Neue"></TextBlock>
<StackPanel HorizontalAlignment="Left" Height="564" Margin="0,76,0,0" VerticalAlignment="Top" Width="400">
<TextBox x:Name="Name" PlaceholderText="Name"></TextBox>
<TextBox x:Name="Price" InputScope="Number" PlaceholderText="Price"></TextBox>
</StackPanel>
<ProgressRing x:Name="Ring" HorizontalAlignment="Center" VerticalAlignment="Center" IsEnabled="True"/>
</Grid>
</Page>
and this is my .cs method were I want to use the ProgressRing:
private void Accept_Click(object sender, RoutedEventArgs e) {
Ring.IsActive = true;
Name.Text = Name.Text.Trim();
Price.Text = Price.Text.Trim();
DBHelper dbHelper = new DBHelper();
Price.Text = Price.Text.Replace(",", ".");
ExpensesTable NewExpense = new ExpensesTable(Place.Id, Name.Text, Convert.ToSingle(Price.Text));
dbHelper.InsertExpense(NewExpense);
Ring.IsActive = false;
Frame.Navigate(typeof(Expenses), Place.Name);
}

I just created sample with code that you provided with simple modifications:
Turn on:
private void Accept_Click(object sender, RoutedEventArgs e)
{
Ring.IsActive = true;
}
Turn off:
private void Cancel_Click(object sender, RoutedEventArgs e)
{
Ring.IsActive = false;
}
Look at the screenshot from emulator:
Also, to remove black rect, you should change Background property to Transparent
So, I guess your code works so fast that you haven't time to see how works ProgressRing.

Related

How to change Flipview object dynamically using c#

i am developing app for windows phone. i am using flipview to show detail. this flipview contains three controls in it and changing view using swipe. i want to change the view on click of button.
See my Code :
<FlipView x:Name="flip" Grid.Row="1" Grid.ColumnSpan="4" Grid.Column="0" Margin="0,0,0,0.333" Grid.RowSpan="2">
<FlipViewItem>
<Button Foreground="White" Background="Black" x:Name="btnAdd" Content="Add" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" Tapped="btnAdd_Tapped" ></Button>
</FlipViewItem>
<FlipViewItem>
<Button x:Name="btny2" Content="mov" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Center" Tapped="btny2_Tapped" ></Button>
</FlipViewItem>
<FlipViewItem>
<Button x:Name="btnUpdate" Content="Upd" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Right" Tapped="btnupdate_Tapped" ></Button>
</FlipViewItem>
<FlipViewItem>
<Button x:Name="btnRemove" Content="Rem" Grid.Row="1" Grid.Column="3" HorizontalAlignment="Center" Tapped="btnRemove_Tapped" ></Button>
</FlipViewItem>
</FlipView>
private void btnAdd_Tapped(object sender, TappedRoutedEventArgs e)
{
flip.SelectedIndex++;
}
private void btnupdate_Tapped(object sender, TappedRoutedEventArgs e)
{
flip.SelectedIndex++;
}
private void btny2_Tapped(object sender, TappedRoutedEventArgs e)
{
flip.SelectedIndex++;
}
private void btnRemove_Tapped(object sender, TappedRoutedEventArgs e)
{
flip.SelectedIndex++;
}
but it is not working at all.
On button click event just increase/decrease selected index..
private void Button_Click_1(object sender, RoutedEventArgs e)
{
SelectedIndex++;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
SelectedIndex--;
}
Try something like this
in .xaml
<FlipView x:Name="flip" Grid.Row="1" Grid.ColumnSpan="4" Grid.Column="0" Margin="0,0,0,0.333" Grid.RowSpan="2">
<Button Foreground="White" Background="Black" x:Name="btnAdd" Content="Add" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" Tapped="btnAdd_Tapped" ></Button>
<Button x:Name="btny2" Content="mov" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Center" Tapped="btny2_Tapped" ></Button>
<Button x:Name="btnUpdate" Content="Upd" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Right" Tapped="btnupdate_Tapped" ></Button>
<Button x:Name="btnRemove" Content="Rem" Grid.Row="1" Grid.Column="3" HorizontalAlignment="Center" Tapped="btnRemove_Tapped" ></Button>
</FlipView>
in .cs
private void Button_Click_1(object sender, RoutedEventArgs e)
{
var newItemIndex = (flip.SelectedIndex + 1)
flip.SelectedIndex = newItemIndex;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var newItemIndex = (flip.SelectedIndex - 1)
flip.SelectedIndex = newItemIndex;
}
I found some work around for same if you put the button outside the flipview and then try to change the index of same then its work
Please look into the following code , Using Grid or Canvas we can easily put the button on Flipview
xaml
<Grid x:Name="LayoutRoot">
<FlipView x:Name="SlideHub" ManipulationMode="Rotate" FlowDirection="LeftToRight" UseTouchAnimationsForAllNavigation="True" Grid.Row="1" >
<FlipViewItem >
</FlipViewItem>
<FlipViewItem >
</FlipViewItem>
<FlipViewItem >
</FlipViewItem>
<FlipViewItem >
</FlipViewItem>
</FlipView>
<Image Tapped="slideBankingNext_tapped" Grid.Row="0" Width="40" Margin="0 10 10 20" HorizontalAlignment="Right" VerticalAlignment="Bottom" Source="/Images/welcome_next.png" />
</Grid>
C# Code
private void slideBankingNext_tapped(object sender, TappedRoutedEventArgs e)
{
var newItemIndex = (SlideHub.SelectedIndex + 1);
SlideHub.SelectedIndex = newItemIndex;
}

how to get the checkbox value from the LongListSelector in wp8

My Longlistselector DataTemplate
<DataTemplate x:Key="NotesListBoxItemTemplate">
<Grid HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<CheckBox
Grid.Column="0" Grid.Row="0" Grid.RowSpan="2"
x:Name="chkDelete"
Visibility="Visible" Tap="chkDelete_Tap" Margin="0,36,0,0" />
<TextBlock
Text="{Binding NoteName}"
FontSize="{StaticResource PhoneFontSizeLarge}"
FontFamily="Segoe WP"
Grid.Row="0" Grid.Column="1" Margin="12,24,0,0" />
</Grid>
</DataTemplate>
and my Longlist selector is
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ScrollViewer>
<phone:LongListSelector
x:Name="MainListBox"
ItemsSource="{Binding AllData}"
Margin="12, 0, 12, 0"
ItemTemplate="{StaticResource ListBoxItemTemplate}" />
</ScrollViewer>
</Grid>
How do I loop through the items and get the Checkbox checked state in each item? Previously I used ListBox and its worked correctly. And I am able to find out the checkbox value of the each item using below code
private T FindFirstElementInVisaulTree<T>(DependencyObject parentElement) where T:DependencyObject
ListBoxItem passed as a DependencyObject. The only problem with ListBox is scrolling. So trying for LongListSelector.
Please how do i loop through the items in LongListSelector.
Thank you
You can also Data Bind the state of the checkbox to your Model. Then you can just loop through the MainListBox.ItemsSource. If you do it this way you need to set the Binding Mode=Two Way or the collection will not change once someone taps the Checkbox. I would also recommend you use a Command to handle the Tap event on the Checkbox so you can handle in your ViewModel rather then Code behind. Here's my quick example modified from previous solutions I have posted:
// Namespaces used
using System.Collections.ObjectModel; // ObservableCollection<T>
using System.ComponentModel; // INotifyPropertyChanged
// sample_data class
public class sample_data : INotifyPropertyChanged
{
// simple constructor
public sample_data(string noteName, Boolean checkboxState)
{
this.NoteName = noteName;
this.CheckboxState = checkboxState;
}
// implement the INotify
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
// {Binding Properties}
Boolean checkbox_state;
public Boolean CheckboxState
{
get { return checkbox_state; }
set { checkbox_state = value; NotifyPropertyChanged("CheckboxState"); }
}
string note_name;
public string NoteName
{
get { return note_name; }
set { note_name = value; NotifyPropertyChanged("NoteName"); }
}
}
// create a sample set of data to show
private ObservableCollection<sample_data> CreateData()
{
ObservableCollection<sample_data> my_list = new ObservableCollection<sample_data>();
my_list.Add(new sample_data("one", false));
my_list.Add(new sample_data("two", true));
my_list.Add(new sample_data("three", false));
my_list.Add(new sample_data("four", true));
my_list.Add(new sample_data("five", false));
my_list.Add(new sample_data("six", true));
my_list.Add(new sample_data("seven", false));
my_list.Add(new sample_data("eight", true));
return my_list;
}
public MainPage()
{
InitializeComponent();
MainListBox.ItemsSource = CreateData(); // set the data bind
}
/// You can loop through the items like this, use any convention you want.
private void LoopThroughItems()
{
foreach (sample_data sd in MainListBox.ItemsSource)
{
Boolean is_check = sd.CheckboxState;
}
}
Your DataTemplate needs to change so it Databinds the checkbox with two-way binding.
<DataTemplate x:Key="NotesListBoxItemTemplate">
<Grid HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<CheckBox Grid.Column="0" IsChecked="{Binding CheckboxState, Mode=TwoWay}" Grid.Row="0" Grid.RowSpan="2" x:Name="chkDelete" Visibility="Visible" Margin="0,36,0,0" />
<TextBlock Text="{Binding NoteName}" FontSize="{StaticResource PhoneFontSizeLarge}" FontFamily="Segoe WP" Grid.Row="0" Grid.Column="1" Margin="12,24,0,0" />
</Grid>
</DataTemplate>

Playing videos from RSS feed in windows phone

I have parsed the RSS feed http://www.teluguone.com/videosongs/videoSongsXml.php?cat_id=6 and displayed in listbox.When i click on a particular song automatically it should be navigated and start playing.But when i click on a song it is navigating to other page but not playing.It was displaying "An error occured please try again".I am not understanding where the problem is.I have written the following code.No errors and warnings are rising.
please help me.i was trying on this from many days.
Maipage.Xaml:
<phone:PhoneApplicationPage
x:Class="videosongs.MainPage"
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"
xmlns:delay="clr-namespace:Delay;assembly=PhonePerformance"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True" Loaded="PhoneApplicationPage_Loaded">
<!--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="Teluguone" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="Videosongs" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ListBox x:Name="songsList"
SelectionChanged="songsList_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="130">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image delay:LowProfileImageLoader.UriSource="{Binding songpic}"
Grid.Column="0"
Width="97"
Height="125"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Margin="6"/>
<StackPanel Margin="10,15,0,0"
Grid.Column="1"
Height="60"
Orientation="Horizontal"
VerticalAlignment="Top">
<TextBlock Text="{Binding songname}"
FontSize="30" />
</StackPanel>
<StackPanel Margin="0,50,0,0"
Grid.Column="1"
VerticalAlignment="Center">
<TextBlock Grid.Column="1"
Text="{Binding songdescr}"
Style='{StaticResource PhoneTextSubtleStyle}'
/>
<TextBlock Grid.Column="1"
Text="{Binding songdate}"
Style='{StaticResource PhoneTextSubtleStyle}'
/>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ProgressBar x:Name="progress" Foreground="White" />
</Grid>
</Grid>
Mainpage.xaml.cs:
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
// is there network connection available
if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
{
MessageBox.Show("No network connection available!");
return;
}
// start loading XML-data
WebClient downloader = new WebClient();
Uri uri = new Uri("http://www.teluguone.com/videosongs/videoSongsXml.php?cat_id=6", UriKind.Absolute);
downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(VideosongsDownloaded);
downloader.DownloadStringAsync(uri);
}
void VideosongsDownloaded(object sender, DownloadStringCompletedEventArgs e)
{
try
{
if (e.Result == null || e.Error != null)
{
MessageBox.Show("There was an error downloading the XML-file!");
}
else
{
// Deserialize if download succeeds
XDocument document = XDocument.Parse(e.Result);
XmlSerializer serializer = new XmlSerializer(typeof(Videosongs));
Videosongs videosongs = (Videosongs)serializer.Deserialize(document.CreateReader());
songsList.ItemsSource = videosongs.Collection;
}
}
catch (Exception ex)
{
//MessageBox.Show(ex.InnerException.Message);
MessageBox.Show(ex.ToString());
}
}
// selection in SongsdetailsList is changed
private void songsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListBox listBox = sender as ListBox;
if (listBox != null && listBox.SelectedItem != null)
{
Songsdetails song = (Songsdetails)listBox.SelectedItem;
System.Diagnostics.Debug.WriteLine(song);
NavigationService.Navigate(new Uri("/Videopage.xaml?songsongcode=" + song.songcode , UriKind.Relative));
}
}
}
}
Songsdetails.cs:
public class Songsdetails
{
[XmlElement("songname")]
public string songname { get; set; }
[XmlElement("songpic")]
public string songpic { get; set; }
[XmlElement("songcode")]
public string songcode { get; set; }
[XmlElement("songdescr")]
public string songdescr { get; set; }
[XmlElement("songtitletags")]
public string songtitletags { get; set; }
[XmlElement("songmetatags")]
public string songmetatags { get; set; }
[XmlElement("songmetadesc")]
public string songmetadesc { get; set; }
[XmlElement("songdate")]
public string songdate { get; set; }
[XmlElement("songurl")]
public string songurl { get; set; }
Videosongs.cs:
[XmlRoot("videosongs")]
public class Videosongs
{
//[XmlElement("publisher")]
//public string publisher { get; set; }
//[XmlElement("publisherurl")]
//public string publisherUrl { get; set; }
[XmlElement("songsdetails")]
public ObservableCollection<Songsdetails> Collection { get; set; }
Videopage.Xaml:
<phone:PhoneApplicationPage
x:Class="videosongs.Videopage"
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"
xmlns:extended="clr-namespace:MyToolkit.Controls;assembly=MyToolkit.Extended"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Landscape"
shell:SystemTray.IsVisible="False">
<StackPanel VerticalAlignment="Top" Height="600" Margin="0,0,0,0">
<TextBlock x:Name="title" TextWrapping="Wrap" VerticalAlignment="Top" Height="40"></TextBlock>
<phone:WebBrowser x:Name="webBrowser" Height="411" IsScriptEnabled="True" Margin="10,0,78,0" />
</StackPanel>
Videopage.Xaml.cs:
namespace videosongs
{
public partial class Videopage : PhoneApplicationPage
{
// Constructor
public Videopage()
{
InitializeComponent();
}
// When page is navigated to set data context to selected item in list
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
if (!NetworkInterface.GetIsNetworkAvailable())
{
MessageBox.Show("An error has occurred! Please verify your internet connection.");
NavigationService.GoBack();
}
else
{
string video = "http://www.youtube.com/embed/+getsongcode()";
System.Diagnostics.Debug.WriteLine(video);
this.webBrowser.Navigate(new Uri(video));
}
}
}
Anybody please help.Any help would be appreciated.
Many Thanks in advance.

Error when trying to tap on LongListSelector

I've made a JumpList (by following this tutorial) linked with a LongListSelector, but I can't redirect the user when he taps on an item of the list. I used to do it well with a simple LongListSelector as this one :
<phone:LongListSelector x:Name="lls_Songs" SelectionChanged=lls_Songs_SelectionChanged>
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Margin="5,5,5,5">
<TextBlock Text="{Binding Name}" FontSize="30"/>
<TextBlock Text="{Binding Duration}" FontSize="20" Opacity="0.75"/>
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
But now I use this code...
<phone:LongListSelector
x:Name="lls_songs"
Margin="12,35,12,0"
Visibility="Visible"
JumpListStyle="{StaticResource JumpListStyle}"
Background="Transparent"
GroupHeaderTemplate="{StaticResource lls_SongsHeaderTemplate}"
ItemTemplate="{StaticResource lls_SongsTemplate}"
LayoutMode="List"
IsGroupingEnabled="true"
SelectionChanged="lls_songs_SelectionChanged"
HideEmptyGroups ="true"/>
...linked with this code :
<DataTemplate x:Key="lls_SongsTemplate">
<StackPanel VerticalAlignment="Top" Orientation="Horizontal" Margin="5,5,5,5">
<StackPanel Orientation="Vertical">
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu>
<toolkit:MenuItem Header="détails"/>
<toolkit:MenuItem Header="ajouter à la lecture"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
<TextBlock Text="{Binding songName}" FontSize="30" />
<TextBlock Text="{Binding songArtist}" FontSize="20" Opacity="0.75"/>
</StackPanel>
</StackPanel>
</DataTemplate>
here is the lls_Songs_SelectionChanged method :
private void lls_songs_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Song _selectedSong = lls_songs.SelectedItem as Song;
MediaPlayer.Play(_selectedSong);
}
and finaly how I create my songs list :
MediaLibrary _library = new MediaLibrary();
List<MusicInfo> MusicInfoList = new List<MusicInfo>();
int so = _library.Songs.Count;
int _so = 0;
while(_so < so)
{
Song _song = null;
_song = _library.Songs[_so];
MusicInfoList.Add(new MusicInfo(_song.Name, _song.Artist.ToString()));
_so = _so + 1;
}
linked with this class:
public string songName { get; set; }
public string songArtist { get; set; }
public MusicInfo(string _songName, string _songArtist)
{
this.songName = _songName;
this.songArtist = _songArtist;
}
and the jumplist :
private void SortingSongsListsAZ()
{
List<AlphaKeyGroup<MusicInfo>> DataSource = AlphaKeyGroup<MusicInfo>.CreateGroups(MusicInfoList,
System.Threading.Thread.CurrentThread.CurrentUICulture,
(MusicInfo s) => { return s.songName; }, true);
lls_songs.ItemsSource = DataSource;
}
And when I tap on an item of the list, I get this error : "This method does not accept null for this parameter". I don't understand why, anyone would help me ?
Share or check your lls_songs items source binding and code. from your code it appears that
Song _selectedSong = lls_songs.SelectedItem as Song;
_selectedSong is null.
in debug mode see what is the value of SelectedItem. is it Song type or something else?
According to your update, it seems that lls_songs.SelectedItem is of type MusicInfo instead of Song. Fixing your type-casting should remove the error I believe :
MusicInfo _selectedSong = lls_songs.SelectedItem as MusicInfo;
Or better yet this way :
MusicInfo _selectedSong = (MusicInfo)lls_songs.SelectedItem;

Viewing the top items in a LongListSelector on WP8 when SIP is open

I have an app that uses a LongListSelector to display a list of items, at the bottom of the page I have a TextBox. When the TextBox is tapped, the SIP displays itself. At this point, I'm unable to then scroll to the top of the LLS.
Sample code:
XAML:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<phone:LongListSelector x:Name="TheList">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"
Style="{StaticResource PhoneTextLargeStyle}"/>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</Grid>
<Grid Grid.Row="1">
<TextBox />
</Grid>
</Grid>
C#:
public MainPage()
{
InitializeComponent();
Loaded += (sender, args) =>
{
var list = new List<string>();
for (var i = 0; i < 30; i++)
{
list.Add("This is string number " + i);
}
TheList.ItemsSource = list;
};
}
This is as much as I can see, I can pull down to string number 5, but can't see any higher:
Anyone got any ideas?
The ScrollViewer doesn't take into account the SIP so its scrolling experience is the same as when the SIP is not visible (which is why the top can't be reached). One workaround would be to add a margin to the top of the LongListSelector, (or the bottom if your textbox is at the top), when the SIP is displayed.
As there's no event for the SIP, you can handle the GotFocus and LostFocus events of the TextBox. (The 180 value was obtained via trial and error)
private void TextBox_GotFocus(object sender, RoutedEventArgs e)
{
TheList.Margin = new Thickness(0,180,0,0);
}
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
{
TheList.Margin = new Thickness();
}