From 0c5aac46b9cd725de31a70c00376567bb02af66b Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Sun, 13 Jan 2013 18:08:09 +0400
Subject: Replace buggy ListBox with ItemsControl+HyperlinkButton, fixes #6
---
Juick/Classes/ScrollViewerMonitor.cs | 25 +---
Juick/MainPage.xaml | 215 ++++++++++++++++++-----------------
Juick/MainPage.xaml.cs | 26 -----
Juick/ViewModels/MessageViewModel.cs | 15 +++
4 files changed, 125 insertions(+), 156 deletions(-)
diff --git a/Juick/Classes/ScrollViewerMonitor.cs b/Juick/Classes/ScrollViewerMonitor.cs
index 6a65773..a985360 100644
--- a/Juick/Classes/ScrollViewerMonitor.cs
+++ b/Juick/Classes/ScrollViewerMonitor.cs
@@ -37,7 +37,7 @@ namespace Juick.Classes
{
var element = (FrameworkElement)sender;
element.Loaded -= element_Loaded;
- var scrollViewer = FindChildOfType(element);
+ var scrollViewer = (ScrollViewer)element.Parent;
if (scrollViewer == null)
{
throw new InvalidOperationException("ScrollViewer not found.");
@@ -59,28 +59,5 @@ namespace Juick.Classes
var binding = new Binding("VerticalOffset") { Source = scrollViewer };
listener.Attach(scrollViewer, binding);
}
-
- static T FindChildOfType(DependencyObject root)
- where T : class
- {
- var queue = new Queue();
- queue.Enqueue(root);
-
- while (queue.Count > 0)
- {
- var current = queue.Dequeue();
- for (int i = VisualTreeHelper.GetChildrenCount(current) - 1; 0 <= i; i--)
- {
- var child = VisualTreeHelper.GetChild(current, i);
- var typedChild = child as T;
- if (typedChild != null)
- {
- return typedChild;
- }
- queue.Enqueue(child);
- }
- }
- return null;
- }
}
}
diff --git a/Juick/MainPage.xaml b/Juick/MainPage.xaml
index a06a305..bffd94f 100644
--- a/Juick/MainPage.xaml
+++ b/Juick/MainPage.xaml
@@ -15,26 +15,26 @@
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
phoneshell:SystemTray.IsVisible="True">
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-
+
-
+
-
-
-
+
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Juick/MainPage.xaml.cs b/Juick/MainPage.xaml.cs
index 8296b18..d6b0b08 100644
--- a/Juick/MainPage.xaml.cs
+++ b/Juick/MainPage.xaml.cs
@@ -159,32 +159,6 @@ namespace Juick
);
}
- private void ListBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- // If selected index is -1 (no selection) do nothing
- if (((ListBox)sender).SelectedIndex == -1)
- return;
-
- // Navigate to the new page
- NavigationService.Navigate(new Uri("/ThreadView.xaml?mid=" + App.MyFeedView.Items[((ListBox)sender).SelectedIndex].MID, UriKind.Relative));
-
- // Reset selected index to -1 (no selection)
- ((ListBox)sender).SelectedIndex = -1;
- }
-
- private void LastBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- // If selected index is -1 (no selection) do nothing
- if (((ListBox)sender).SelectedIndex == -1)
- return;
-
- // Navigate to the new page
- NavigationService.Navigate(new Uri(string.Format("/ThreadView.xaml?mid={0}", App.LastView.Items[((ListBox)sender).SelectedIndex].MID), UriKind.Relative));
-
- // Reset selected index to -1 (no selection)
- ((ListBox)sender).SelectedIndex = -1;
- }
-
private void ApplicationBarIconButtonClick(object sender, EventArgs e)
{
App.MyFeedView.Items.Clear();
diff --git a/Juick/ViewModels/MessageViewModel.cs b/Juick/ViewModels/MessageViewModel.cs
index e120c5d..460df38 100644
--- a/Juick/ViewModels/MessageViewModel.cs
+++ b/Juick/ViewModels/MessageViewModel.cs
@@ -17,6 +17,7 @@ namespace Juick.ViewModels
public MessageViewModel(Message message)
{
MID = message.Mid;
+ MessageUri = string.Format("/ThreadView.xaml?mid={0}", MID);
RID = message.Rid;
Username = message.User.UName;
MessageText = HttpUtility.HtmlDecode(message.Body);
@@ -138,6 +139,8 @@ namespace Juick.ViewModels
}
private string _status;
+
+
///
/// Sample _viewModelBase property; this property is used in the view to display its value using a Binding.
///
@@ -158,6 +161,18 @@ namespace Juick.ViewModels
}
}
+ private string _messageUri;
+
+ public string MessageUri
+ {
+ get { return _messageUri; }
+ set
+ {
+ _messageUri = value;
+ NotifyPropertyChanged("MessageUri");
+ }
+ }
+
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(String propertyName)
--
cgit v1.2.3