From 4c803da166e9f4111ca0d11d3585c0760aed5260 Mon Sep 17 00:00:00 2001 From: Christian Fiedler Date: Thu, 10 Oct 2013 18:12:58 +0200 Subject: [PATCH] fixed #220 --- CampusAppWP8/CampusAppWP8/App.xaml | 1 + CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj | 1 + .../CampusAppWP8/Pages/Events/EventPage.xaml | 6 +-- .../Pages/Events/EventPage.xaml.cs | 35 ++++++------ .../CampusAppWP8/Pages/News/NewsPage.xaml | 4 +- .../CampusAppWP8/Pages/News/NewsPage.xaml.cs | 33 +++++------- .../Utility/BoolToVisibilityConverter.cs | 26 +++++++++ .../CampusAppWP8/Utility/Utilities.cs | 54 +++++++++---------- .../Model/RSS/RSSModel.cs | 49 ++++++++++++++++- 9 files changed, 134 insertions(+), 75 deletions(-) create mode 100644 CampusAppWP8/CampusAppWP8/Utility/BoolToVisibilityConverter.cs diff --git a/CampusAppWP8/CampusAppWP8/App.xaml b/CampusAppWP8/CampusAppWP8/App.xaml index a4aef1d3..282eda77 100644 --- a/CampusAppWP8/CampusAppWP8/App.xaml +++ b/CampusAppWP8/CampusAppWP8/App.xaml @@ -16,6 +16,7 @@ + diff --git a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj index e9db4ecf..0a33d7ad 100644 --- a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj +++ b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj @@ -162,6 +162,7 @@ + DefaultHeader.xaml diff --git a/CampusAppWP8/CampusAppWP8/Pages/Events/EventPage.xaml b/CampusAppWP8/CampusAppWP8/Pages/Events/EventPage.xaml index 8e1898c6..27d815f8 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Events/EventPage.xaml +++ b/CampusAppWP8/CampusAppWP8/Pages/Events/EventPage.xaml @@ -32,14 +32,14 @@ - + - + @@ -51,7 +51,7 @@ - + diff --git a/CampusAppWP8/CampusAppWP8/Pages/Events/EventPage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Events/EventPage.xaml.cs index ec6c2600..646fc13b 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Events/EventPage.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/Events/EventPage.xaml.cs @@ -20,6 +20,8 @@ namespace CampusAppWP8.Pages.Events using Windows.Phone.Speech.Synthesis; using CampusAppWPortalLib8.Model.RSS; + using System.Windows.Media; + /// /// EventPage, where every event feed has his own PivotItem. /// @@ -32,11 +34,6 @@ namespace CampusAppWP8.Pages.Events /// private bool isSourceSet = false; - /// - /// To store the last selected pivot index. - /// - private int lastSelectedIndex = -1; - /// /// For checking if the instance is back from tombstone. /// @@ -181,15 +178,15 @@ namespace CampusAppWP8.Pages.Events /// event args private void OnPivotSelectionChange(object sender, SelectionChangedEventArgs e) { - int selIndex = (sender as Pivot).SelectedIndex; - - if (this.lastSelectedIndex > -1) + if (e.RemovedItems.Count > 0) { - Utilities.SetElementVisibility(this.EventPivot, "EventParentGrid", "EventWebBrowser", Visibility.Collapsed, this.lastSelectedIndex); - Utilities.SetElementVisibility(this.EventPivot, "EventParentGrid", "EventTextGrid", Visibility.Visible, this.lastSelectedIndex); - } + RSSModel last = e.RemovedItems[0] as RSSModel; - this.lastSelectedIndex = selIndex; + if (last != null && last.TextVisibility == false) + { + last.TextVisibility = true; + } + } } /// @@ -201,15 +198,13 @@ namespace CampusAppWP8.Pages.Events /// event args private void EventLink_Click(object sender, EventArgs e) { - if (Visibility.Visible == Utilities.GetElementVisibility(this.EventPivot, "EventParentGrid", "EventTextGrid", this.EventPivot.SelectedIndex)) + RSSModel cur = this.EventPivot.SelectedItem as RSSModel; + + this.EventPivot.UpdateLayout(); + + if (cur != null) { - Utilities.SetElementVisibility(this.EventPivot, "EventParentGrid", "EventTextGrid", Visibility.Collapsed, this.EventPivot.SelectedIndex); - Utilities.SetElementVisibility(this.EventPivot, "EventParentGrid", "EventWebBrowser", Visibility.Visible, this.EventPivot.SelectedIndex); - } - else - { - Utilities.SetElementVisibility(this.EventPivot, "EventParentGrid", "EventWebBrowser", Visibility.Collapsed, this.EventPivot.SelectedIndex); - Utilities.SetElementVisibility(this.EventPivot, "EventParentGrid", "EventTextGrid", Visibility.Visible, this.EventPivot.SelectedIndex); + cur.TextVisibility = (cur.TextVisibility) ? false : true; } } diff --git a/CampusAppWP8/CampusAppWP8/Pages/News/NewsPage.xaml b/CampusAppWP8/CampusAppWP8/Pages/News/NewsPage.xaml index 99ee0fac..797ae08c 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/News/NewsPage.xaml +++ b/CampusAppWP8/CampusAppWP8/Pages/News/NewsPage.xaml @@ -38,7 +38,7 @@ - + @@ -50,7 +50,7 @@ - + diff --git a/CampusAppWP8/CampusAppWP8/Pages/News/NewsPage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/News/NewsPage.xaml.cs index 7739fd17..4ce80301 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/News/NewsPage.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/News/NewsPage.xaml.cs @@ -30,11 +30,6 @@ namespace CampusAppWP8.Pages.News /// private bool isSourceSet = false; - /// - /// To store the index of the last selected PivotItem. - /// - private int lastSelectedIndex = -1; - /// /// For checking if the instance is back from tombstone. /// @@ -176,15 +171,15 @@ namespace CampusAppWP8.Pages.News /// event args private void OnPivotSelectionChange(object sender, SelectionChangedEventArgs e) { - int selIndex = (sender as Pivot).SelectedIndex; - - if (this.lastSelectedIndex > -1) + if (e.RemovedItems.Count > 0) { - Utilities.SetElementVisibility(this.NewsPivot, "NewsParentGrid", "NewsWebBrowser", Visibility.Collapsed, this.lastSelectedIndex); - Utilities.SetElementVisibility(this.NewsPivot, "NewsParentGrid", "NewsTextGrid", Visibility.Visible, this.lastSelectedIndex); - } + RSSModel last = e.RemovedItems[0] as RSSModel; - this.lastSelectedIndex = selIndex; + if (last != null && last.TextVisibility == false) + { + last.TextVisibility = true; + } + } } /// @@ -196,15 +191,13 @@ namespace CampusAppWP8.Pages.News /// event args private void NewsLink_Click(object sender, EventArgs e) { - if (Visibility.Visible == Utilities.GetElementVisibility(this.NewsPivot, "NewsParentGrid", "NewsTextGrid", this.NewsPivot.SelectedIndex)) + RSSModel cur = this.NewsPivot.SelectedItem as RSSModel; + + this.NewsPivot.UpdateLayout(); + + if (cur != null) { - Utilities.SetElementVisibility(this.NewsPivot, "NewsParentGrid", "NewsTextGrid", Visibility.Collapsed, this.NewsPivot.SelectedIndex); - Utilities.SetElementVisibility(this.NewsPivot, "NewsParentGrid", "NewsWebBrowser", Visibility.Visible, this.NewsPivot.SelectedIndex); - } - else - { - Utilities.SetElementVisibility(this.NewsPivot, "NewsParentGrid", "NewsWebBrowser", Visibility.Collapsed, this.NewsPivot.SelectedIndex); - Utilities.SetElementVisibility(this.NewsPivot, "NewsParentGrid", "NewsTextGrid", Visibility.Visible, this.NewsPivot.SelectedIndex); + cur.TextVisibility = (cur.TextVisibility) ? false : true; } } diff --git a/CampusAppWP8/CampusAppWP8/Utility/BoolToVisibilityConverter.cs b/CampusAppWP8/CampusAppWP8/Utility/BoolToVisibilityConverter.cs new file mode 100644 index 00000000..83ed3adc --- /dev/null +++ b/CampusAppWP8/CampusAppWP8/Utility/BoolToVisibilityConverter.cs @@ -0,0 +1,26 @@ +//----------------------------------------------------------------------------- +// +// Company copyright tag. +// +// fiedlchr +// 10.10.2013 +//----------------------------------------------------------------------------- +namespace CampusAppWP8.Utility +{ + using System; + using System.Windows; + using System.Windows.Data; + + public sealed class BoolToVisibilityConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo language) + { + return (value is bool && (bool)value) ? Visibility.Visible : Visibility.Collapsed; + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo language) + { + return (value is Visibility && (Visibility)value == Visibility.Visible); + } + } +} diff --git a/CampusAppWP8/CampusAppWP8/Utility/Utilities.cs b/CampusAppWP8/CampusAppWP8/Utility/Utilities.cs index 306dcf2b..ffdf3f15 100644 --- a/CampusAppWP8/CampusAppWP8/Utility/Utilities.cs +++ b/CampusAppWP8/CampusAppWP8/Utility/Utilities.cs @@ -136,22 +136,22 @@ namespace CampusAppWP8.Utility } /// - /// Search for a UIElement with the specified name in the parent Grid and set its visibility. + /// Return the element. /// - /// root object - /// name of the parent grid - /// name of the UIElement - /// new visibility property state - /// index of the element in the parent child list - public static void SetElementVisibility(DependencyObject rootObj, string parentGridName, string elemName, Visibility vis, int index = 0) + /// + /// + /// + /// + /// + public static FrameworkElement GetElement(DependencyObject rootObj, string parentGridName, string elemName, int index = 0) { List l = Utilities.GetChild(rootObj, parentGridName); - // hotfix: OutofRangeIndex Assert if (index > l.Count - 1) { - return; + throw new IndexOutOfRangeException("index (" + index + ") out of range (<" + l.Count + ")"); } + Grid parentGrid = l[index] as Grid; FrameworkElement elem = null; @@ -163,6 +163,21 @@ namespace CampusAppWP8.Utility } } + return elem; + } + + /// + /// Search for a UIElement with the specified name in the parent Grid and set its visibility. + /// + /// root object + /// name of the parent grid + /// name of the UIElement + /// new visibility property state + /// index of the element in the parent child list + public static void SetElementVisibility(DependencyObject rootObj, string parentGridName, string elemName, Visibility vis, int index = 0) + { + FrameworkElement elem = GetElement(rootObj, parentGridName, elemName, index); + if (elem != null) { elem.Visibility = vis; @@ -180,25 +195,8 @@ namespace CampusAppWP8.Utility public static Visibility GetElementVisibility(DependencyObject rootObj, string parentGridName, string elemName, int index = 0) { Visibility retValue; - - List l = Utilities.GetChild(rootObj, parentGridName); - - if (index >= l.Count) - { - index = 0; - } - - Grid parentGrid = l[index] as Grid; - FrameworkElement elem = null; - - foreach (FrameworkElement tempElem in parentGrid.Children) - { - if (tempElem.Name == elemName) - { - elem = tempElem; - } - } - + FrameworkElement elem = GetElement(rootObj, parentGridName, elemName, index); + if (elem != null) { retValue = elem.Visibility; diff --git a/CampusAppWP8/CampusAppWPortalLib8/Model/RSS/RSSModel.cs b/CampusAppWP8/CampusAppWPortalLib8/Model/RSS/RSSModel.cs index 32b6afb7..6d5efa62 100644 --- a/CampusAppWP8/CampusAppWPortalLib8/Model/RSS/RSSModel.cs +++ b/CampusAppWP8/CampusAppWPortalLib8/Model/RSS/RSSModel.cs @@ -10,13 +10,16 @@ namespace CampusAppWPortalLib8.Model.RSS using System; using System.Text; using System.Xml.Serialization; + using System.ComponentModel; /// /// Contains the RSS feed information. /// - public class RSSModel + public class RSSModel : INotifyPropertyChanged { #region Member + + public event PropertyChangedEventHandler PropertyChanged; /// /// Index of this object. @@ -43,8 +46,10 @@ namespace CampusAppWPortalLib8.Model.RSS /// private string link; - #endregion + private bool textVisible = true; + #endregion + #region Property /// @@ -195,6 +200,38 @@ namespace CampusAppWPortalLib8.Model.RSS } } + /// + /// Gets or sets the visibility of the text. + /// + public bool TextVisibility + { + get + { + return this.textVisible; + } + + set + { + if (value != this.textVisible) + { + this.textVisible = value; + this.NotifyPropertyChanged("TextVisibility"); + this.NotifyPropertyChanged("BrowserVisibility"); + } + } + } + + /// + /// Gets or sets the visibility of the browser. + /// + public bool BrowserVisibility + { + get + { + return !this.textVisible; + } + } + #endregion #region Method @@ -224,6 +261,14 @@ namespace CampusAppWPortalLib8.Model.RSS #region private + private void NotifyPropertyChanged(string info) + { + if (PropertyChanged != null) + { + this.PropertyChanged(this, new PropertyChangedEventArgs(info)); + } + } + /// /// Remove or transform html-unicode specific tags into ASCII. ///