diff --git a/.gitignore b/.gitignore index 70ac09cd..676a854a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ *.user *.userosscache *.sln.docstates +sync.cmd # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/Samples/SampleDeviceCollection/App.config b/Samples/SampleDeviceCollection/App.config new file mode 100644 index 00000000..88fa4027 --- /dev/null +++ b/Samples/SampleDeviceCollection/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Samples/SampleDeviceCollection/App.xaml b/Samples/SampleDeviceCollection/App.xaml new file mode 100644 index 00000000..072cc6c8 --- /dev/null +++ b/Samples/SampleDeviceCollection/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/Samples/SampleDeviceCollection/App.xaml.cs b/Samples/SampleDeviceCollection/App.xaml.cs new file mode 100644 index 00000000..f0e468ac --- /dev/null +++ b/Samples/SampleDeviceCollection/App.xaml.cs @@ -0,0 +1,16 @@ +//---------------------------------------------------------------------------------------------- +// +// Licensed under the MIT License. See LICENSE.TXT in the project root license information. +// +//---------------------------------------------------------------------------------------------- +using System.Windows; + +namespace SampleDeviceCollection +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/Samples/SampleDeviceCollection/BooleanConverter.cs b/Samples/SampleDeviceCollection/BooleanConverter.cs new file mode 100644 index 00000000..57665166 --- /dev/null +++ b/Samples/SampleDeviceCollection/BooleanConverter.cs @@ -0,0 +1,105 @@ +//---------------------------------------------------------------------------------------------- +// +// Licensed under the MIT License. See LICENSE.TXT in the project root license information. +// +//---------------------------------------------------------------------------------------------- +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Windows; +using System.Windows.Data; + +namespace SampleDeviceCollection +{ + //------------------------------------------------------------------- + // Boolean Converter + //------------------------------------------------------------------- + #region Boolean Converter + /// + /// Template allows for easy creation of a value converter for bools + /// + /// Type to convert back and forth to boolean + /// + /// See BooleanToVisibilityConverter and BooleanToBrushConverter (below) and usage in Generic.xaml + /// + public class BooleanConverter : IValueConverter + { + /// + /// Initializes a new instance of the class. + /// + /// The value of type T that represents true + /// The value of type T that represents false + public BooleanConverter(T trueValue, T falseValue) + { + this.True = trueValue; + this.False = falseValue; + } + + /// + /// Gets or sets the value that represents true + /// + public T True { get; set; } + + /// + /// Gets or sets the value that represetns false + /// + public T False { get; set; } + + /// + /// Convert an object of type T to boolean + /// + /// Object of type T to convert + /// The parameter is not used. + /// The parameter is not used. + /// The parameter is not used. + /// Object of boolean value + public virtual object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return value is bool && ((bool)value) ? this.True : this.False; + } + + /// + /// Convert a boolean value to an object of type T + /// + /// The boolean value to convert + /// The parameter is not used. + /// The parameter is not used. + /// The parameter is not used. + /// Object of type T + public virtual object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return value is T && EqualityComparer.Default.Equals((T)value, this.True); + } + } + + /// + /// Converter between a boolean and visibility value + /// + [type: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "Small classes are all instances of the same generic and are better organized in a single file.")] + public sealed class BooleanToVisibilityConverter : BooleanConverter + { + /// + /// Initializes a new instance of the class. + /// + public BooleanToVisibilityConverter() : + base(Visibility.Visible, Visibility.Hidden) + { + } + } + + /// + /// Converter between a boolean and either "http" or "https" + /// + [type: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "Small classes are all instances of the same generic and are better organized in a single file.")] + public sealed class BooleanToHttpsConverter : BooleanConverter + { + /// + /// Initializes a new instance of the class. + /// + public BooleanToHttpsConverter() : + base("https", "http") + { + } + } + #endregion // Boolean Converter +} diff --git a/Samples/SampleDeviceCollection/Controls/AutoScrollTextBox.cs b/Samples/SampleDeviceCollection/Controls/AutoScrollTextBox.cs new file mode 100644 index 00000000..0372169a --- /dev/null +++ b/Samples/SampleDeviceCollection/Controls/AutoScrollTextBox.cs @@ -0,0 +1,36 @@ +//---------------------------------------------------------------------------------------------- +// +// Licensed under the MIT License. See LICENSE.TXT in the project root license information. +// +//---------------------------------------------------------------------------------------------- +using System.Windows; +using System.Windows.Controls; + +namespace SampleDeviceCollection +{ + /// + /// A TextBox derrivative that automatically scrolls to end whenever new text is added. + /// This is used for presenting scrolling output spew. + /// + public class AutoScrollTextBox : TextBox + { + /// + /// Initializes static members of the class. + /// + static AutoScrollTextBox() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(AutoScrollTextBox), new FrameworkPropertyMetadata(typeof(AutoScrollTextBox))); + } + + /// + /// Override OnTextChanged to automatically scroll to the end + /// + /// The arguments associated with this event + protected override void OnTextChanged(TextChangedEventArgs e) + { + base.OnTextChanged(e); + this.CaretIndex = Text.Length; + this.ScrollToEnd(); + } + } +} diff --git a/Samples/SampleDeviceCollection/Controls/BindablePassword.xaml b/Samples/SampleDeviceCollection/Controls/BindablePassword.xaml new file mode 100644 index 00000000..88277aff --- /dev/null +++ b/Samples/SampleDeviceCollection/Controls/BindablePassword.xaml @@ -0,0 +1,11 @@ + + + + + diff --git a/Samples/SampleDeviceCollection/Controls/BindablePassword.xaml.cs b/Samples/SampleDeviceCollection/Controls/BindablePassword.xaml.cs new file mode 100644 index 00000000..06e4dfef --- /dev/null +++ b/Samples/SampleDeviceCollection/Controls/BindablePassword.xaml.cs @@ -0,0 +1,73 @@ +//---------------------------------------------------------------------------------------------- +// +// Licensed under the MIT License. See LICENSE.TXT in the project root license information. +// +//---------------------------------------------------------------------------------------------- +using System.Security; +using System.Windows; +using System.Windows.Controls; + +namespace SampleDeviceCollection +{ + /// + /// Interaction logic for BindablePassword.xaml + /// + public partial class BindablePassword : UserControl + { + //------------------------------------------------------------------- + // Constructors + //------------------------------------------------------------------- + #region Constructors + /// + /// Initializes a new instance of the class. + /// + public BindablePassword() + { + this.InitializeComponent(); + } + #endregion // Constructors + + //------------------------------------------------------------------- + // Dependency Properties + //------------------------------------------------------------------- + #region Dependency Properties + #region Password Dependency Property + /// + /// Gets or sets the Password dependency property + /// + public SecureString Password + { + get + { + return (SecureString)GetValue(PasswordProperty); + } + + set + { + this.SetValue(PasswordProperty, value); + } + } + + /// + /// Password Dependeny Property static association + /// + public static readonly DependencyProperty PasswordProperty = + DependencyProperty.Register( + "Password", + typeof(SecureString), + typeof(BindablePassword), + new PropertyMetadata(default(SecureString))); + + /// + /// Forwards change events to the password box's secure string to the Password dependency property + /// + /// object that originated the event + /// Parameters for the event + private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e) + { + this.Password = ((PasswordBox)sender).SecurePassword; + } + #endregion // Password Dependency Property + #endregion // Dependency Properties + } +} diff --git a/Samples/SampleDeviceCollection/Controls/DeviceCollectionView.xaml b/Samples/SampleDeviceCollection/Controls/DeviceCollectionView.xaml new file mode 100644 index 00000000..f1784eba --- /dev/null +++ b/Samples/SampleDeviceCollection/Controls/DeviceCollectionView.xaml @@ -0,0 +1,232 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +