Files
win8phoneApp/CampusAppWP8/CampusAppWP8/Utility/Lui/Button/NavigateButton.cs
Christian Fiedler 11016d033f temp commit
2013-11-26 16:21:30 +01:00

108 lines
3.9 KiB
C#

//-----------------------------------------------------------------------
// <copyright file="NavigateButton.cs" company="BTU/IIT">
// The MIT License (MIT). Copyright (c) 2013 BTU/IIT.
// </copyright>
// <author>Stubbfel</author>
// <date>15.10.2013</date>
// <summary>Implements the navigate button class</summary>
//-----------------------------------------------------------------------
namespace CampusAppWP8.Utility.Lui.Button
{
using System;
using System.Windows;
using System.Windows.Controls;
/// <summary> This class create an Button which navigate to a certain page. </summary>
/// <remarks> Stubbfel, 15.10.2013. </remarks>
/// <seealso cref="T:System.Windows.Controls.Button"/>
public class NavigateButton : System.Windows.Controls.Button
{
#region Members
/// <summary> Register the UrlProperty. </summary>
public static readonly DependencyProperty NavigateProperty = DependencyProperty.Register("Url", typeof(object), typeof(NavigateButton), new PropertyMetadata(false));
/// <summary> Register the QueryValueProperty. </summary>
public static readonly DependencyProperty QueryValueProperty = DependencyProperty.Register("QuerryStringValue", typeof(object), typeof(NavigateButton), new PropertyMetadata(false));
/// <summary> Register the QueryNameProperty. </summary>
public static readonly DependencyProperty QueryNameProperty = DependencyProperty.Register("QuerryStringName", typeof(object), typeof(NavigateButton), new PropertyMetadata(false));
#endregion
#region Constructors
/// <summary> Initializes a new instance of the <see cref="NavigateButton" /> class. </summary>
/// <remarks> Stubbfel, 15.10.2013. </remarks>
public NavigateButton()
: base()
{
}
#endregion
#region Proberties
/// <summary> Gets or sets the Url. </summary>
/// <value> The URL. </value>
public object Url
{
get { return (object)this.GetValue(NavigateProperty); }
set { this.SetValue(NavigateProperty, value); }
}
/// <summary> Gets or sets the QueryStringName. </summary>
/// <value> The name of the query string. </value>
public object QuerryStringName
{
get { return (object)this.GetValue(QueryNameProperty); }
set { this.SetValue(QueryNameProperty, value); }
}
/// <summary> Gets or sets the QueryStringValue. </summary>
/// <value> The query string value. </value>
public object QuerryStringValue
{
get { return (object)this.GetValue(QueryValueProperty); }
set { this.SetValue(QueryValueProperty, value); }
}
#endregion
#region Methods
/// <summary> Overrides the OnClick-Method from button. </summary>
/// <remarks> now method navigate to a certain page. </remarks>
/// <seealso cref="M:System.Windows.Controls.Button.OnClick()"/>
protected override void OnClick()
{
base.OnClick();
string urlString = string.Empty;
if (this.Url is string)
{
urlString = this.Url as string;
}
else if (this.Url is Uri)
{
urlString = ((Uri)this.Url).OriginalString;
}
else
{
throw new NotSupportedException("Url has a unsupported type");
}
if (this.QuerryStringName != null && this.QuerryStringValue != null)
{
urlString += "?" + this.QuerryStringName + "=" + this.QuerryStringValue;
}
Uri url = new Uri(urlString as string, UriKind.Relative);
Page page = App.RootFrame.Content as Page;
page.NavigationService.Navigate(url);
}
#endregion
}
}