Mercurial > silverbladetech
changeset 62:810116cd6b8e
ErrorWindow working
line wrap: on
line diff
--- a/SilverlightGlimpse/Controls/BrokenBindingsViewer.xaml Sat Apr 21 21:20:05 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -<UserControl x:Class="SilverlightGlimpse.Controls.BrokenBindingsViewer" - xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> - <Grid x:Name="LayoutRoot" Background="White"> - <ScrollViewer> - <ItemsControl x:Name="icBrokenBindings" /> - </ScrollViewer> - </Grid> -</UserControl>
--- a/SilverlightGlimpse/Controls/BrokenBindingsViewer.xaml.cs Sat Apr 21 21:20:05 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -using System.Reflection; -using System.Windows.Data; -using SilverlightGlimpse.Models; -using System.Windows; -using System.Diagnostics; -using System.Windows.Media; -using SilverlightGlimpse.Services; - -namespace SilverlightGlimpse.Controls -{ - public partial class BrokenBindingsViewer - { - public BrokenBindingsViewer() - { - InitializeComponent(); - } - - private void BrokenBindings_Loaded(object sender, RoutedEventArgs e) - { - this.icBrokenBindings.Items.Clear(); - LoadBrokenBindings(GlimpseService.CreateInstance.RootVisual); - } - - private void LoadBrokenBindings(UIElement uiElement) - { - var frameworkElement = uiElement as FrameworkElement; - - if (frameworkElement != null) - { - foreach (var fieldInfo in frameworkElement.GetType().GetFields(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Static)) - { - if (object.ReferenceEquals(fieldInfo.FieldType, typeof(DependencyProperty))) - { - var bindingExpression = frameworkElement.GetBindingExpression((DependencyProperty)fieldInfo.GetValue(null)); - - if (bindingExpression != null && bindingExpression.ParentBinding.Source == null && bindingExpression.ParentBinding.RelativeSource == null) - { - var isInherited = false; - - if (frameworkElement.DataContext != null && !string.IsNullOrEmpty(bindingExpression.ParentBinding.Path.Path)) - { - foreach (var propertyInfo in frameworkElement.DataContext.GetType().GetProperties(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Instance)) - { - if (string.Compare(propertyInfo.Name, bindingExpression.ParentBinding.Path.Path) == 0) - { - isInherited = true; - break; // TODO: might not be correct. Was : Exit For - } - } - } - - if (isInherited) - { - break; // TODO: might not be correct. Was : Exit For - } - - //this code handles empty bindings on the Button controls - //I'll have to look into why the Button has an empty or unresolved binding - if (string.IsNullOrEmpty(frameworkElement.Name) - && frameworkElement.GetType().Name == "TextBlock" - && fieldInfo.Name == "TextProperty" - && string.IsNullOrEmpty(bindingExpression.ParentBinding.Path.Path)) - { - break; // TODO: might not be correct. Was : Exit For - } - - BrokenBinding objBrokenBinding = new BrokenBinding( - frameworkElement.Name, - frameworkElement.GetType().Name, - fieldInfo.Name, - bindingExpression.ParentBinding.Path.Path); - this.icBrokenBindings.Items.Add(objBrokenBinding); - Debug.WriteLine("Broken Binding - ", objBrokenBinding.ToString()); - } - } - } - - int children = VisualTreeHelper.GetChildrenCount(frameworkElement); - - for (int j = 0; j <= children - 1; j++) - { - FrameworkElement child = VisualTreeHelper.GetChild(frameworkElement, j) as FrameworkElement; - - if (child != null) - { - LoadBrokenBindings(child); - } - } - } - } - } -} \ No newline at end of file
--- a/SilverlightGlimpse/Controls/ExceptionsViewer.xaml Sat Apr 21 21:20:05 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -<UserControl x:Class="SilverlightGlimpse.Controls.ExceptionsViewer" - xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> - <Grid x:Name="LayoutRoot" Background="White"> - <Grid.ColumnDefinitions> - <ColumnDefinition Width="250" /> - <ColumnDefinition Width="*" /> - </Grid.ColumnDefinitions> - <Grid.RowDefinitions> - <RowDefinition Height="Auto" /> - <RowDefinition Height="*" /> - <RowDefinition Height="Auto" /> - </Grid.RowDefinitions> - - <TextBlock Grid.ColumnSpan="2" - Margin="3.5" - VerticalAlignment="Center" - FontSize="18" - Foreground="Red" - Text="Exceptions Viewer" /> - - <ListBox x:Name="lbExceptions" - Grid.Row="1" - Margin="3.5" - ItemsSource="{Binding}" - SelectionChanged="lbExceptions_SelectionChanged" /> - - <ScrollViewer Grid.Row="1" - Grid.Column="1" - Margin="3.5" - DataContext="{Binding ElementName=lbExceptions, - Path=SelectedItem}"> - <Grid> - <Grid.RowDefinitions> - <RowDefinition Height="Auto" /> - <RowDefinition Height="Auto" /> - <RowDefinition Height="Auto" /> - <RowDefinition Height="Auto" /> - <RowDefinition Height="Auto" /> - <RowDefinition Height="Auto" /> - <RowDefinition Height="Auto" /> - <RowDefinition Height="Auto" /> - </Grid.RowDefinitions> - - <Rectangle Fill="BlanchedAlmond" /> - <TextBlock x:Name="tbAction" - FontSize="14" - Text="Action" - TextDecorations="Underline" /> - <TextBlock Grid.Row="1" - FontSize="11" - Text="{Binding Path=Action}" - TextWrapping="Wrap" - Visibility="{Binding ElementName=tbAction, - Path=Visibility}" /> - - <Rectangle Grid.Row="2" Fill="BlanchedAlmond" /> - <TextBlock Grid.Row="2" - Margin="0,7,0,0" - FontSize="14" - Text="Control Name" - TextDecorations="Underline" - Visibility="{Binding ElementName=tbAction, - Path=Visibility}" /> - <TextBlock Grid.Row="3" - FontSize="11" - Text="{Binding Path=ControlName}" - TextWrapping="Wrap" - Visibility="{Binding ElementName=tbAction, - Path=Visibility}" /> - - <Rectangle Grid.Row="4" Fill="BlanchedAlmond" /> - <TextBlock Grid.Row="4" - Margin="0,7,0,0" - FontSize="14" - Text="Message" - TextDecorations="Underline" /> - <TextBlock Grid.Row="5" - FontSize="11" - Text="{Binding Path=Exception.Message}" - TextWrapping="Wrap" /> - - <Rectangle Grid.Row="6" Fill="BlanchedAlmond" /> - <TextBlock Grid.Row="6" - Margin="0,7,0,0" - FontSize="14" - Text="Stack Trace" - TextDecorations="Underline" /> - <TextBlock Grid.Row="7" - FontSize="11" - Text="{Binding Path=Exception.StackTrace}" - TextWrapping="Wrap" /> - - </Grid> - </ScrollViewer> - <Button Grid.Row="2" - Grid.Column="1" - Margin="11" - HorizontalAlignment="Right" - VerticalAlignment="Center" - Click="ClearExceptions_Click" - Content="Clear Exceptions" - Padding="7" /> - </Grid> -</UserControl>
--- a/SilverlightGlimpse/Controls/ExceptionsViewer.xaml.cs Sat Apr 21 21:20:05 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -using System; -using System.Windows; -using SilverlightGlimpse.Models; -using System.Windows.Controls; -using SilverlightGlimpse.Services; - -namespace SilverlightGlimpse.Controls -{ - public partial class ExceptionsViewer - { - public ExceptionsViewer() - { - InitializeComponent(); - } - - private void ClearExceptions_Click(object sender, RoutedEventArgs e) - { - GlimpseService.CreateInstance.HostExceptions.Clear(); - } - - private void ExceptionsViewer_Loaded(object sender, RoutedEventArgs e) - { - this.DataContext = GlimpseService.CreateInstance.HostExceptions; - if (GlimpseService.CreateInstance.HostExceptions.Count > 0) - this.lbExceptions.SelectedIndex = 0; - } - - private void lbExceptions_SelectionChanged(object sender, SelectionChangedEventArgs e) - { - if (this.lbExceptions.SelectedItem != null && this.lbExceptions.SelectedItem is ExceptionWrapper) - { - if (((ExceptionWrapper)this.lbExceptions.SelectedItem).IsValidationException) - this.tbAction.Visibility = Visibility.Visible; - else - this.tbAction.Visibility = Visibility.Collapsed; - } - } - } -} \ No newline at end of file
--- a/SilverlightGlimpse/Controls/GlimpseViewer.xaml Sat Apr 21 21:20:05 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -<UserControl x:Class="SilverlightGlimpse.Controls.GlimpseViewer" - xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:c="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" - xmlns:localc="clr-namespace:SilverlightGlimpse.Controls"> - <Grid x:Name="LayoutRoot" Background="Khaki"> - <Grid.Resources> - <SolidColorBrush x:Name="noExceptionsBrush" Color="LightGreen" /> - <SolidColorBrush x:Name="hasExceptionsBrush" Color="Red" /> - </Grid.Resources> - <Grid x:Name="layoutInstrumentPanel"> - <StackPanel Orientation="Horizontal"> - <Grid Margin="7"> - <Ellipse x:Name="elpValidationExceptions" - Width="40" - Height="40" - Fill="LightGreen" - Stroke="Brown" - StrokeThickness="2" /> - <TextBlock x:Name="tbValidationExceptions" - HorizontalAlignment="Center" - VerticalAlignment="Center" - FontSize="12" - FontWeight="Bold" - Text="0" - ToolTipService.ToolTip="Binding Exception Count" /> - </Grid> - <Grid Margin="7"> - <Ellipse x:Name="elpUnhandledExceptions" - Width="40" - Height="40" - Fill="LightGreen" - Stroke="Brown" - StrokeThickness="2" /> - <TextBlock x:Name="tbUnhandledExceptions" - HorizontalAlignment="Center" - VerticalAlignment="Center" - FontSize="12" - FontWeight="Bold" - Text="0" - ToolTipService.ToolTip="Unhandled Exception Count" /> - </Grid> - <Button x:Name="btnExpand" - Margin="7" - VerticalAlignment="Center" - Content="Expand" /> - </StackPanel> - </Grid> - <Grid x:Name="layoutViewer" Visibility="Collapsed"> - <Grid.RowDefinitions> - <RowDefinition Height="Auto" /> - <RowDefinition Height="*" /> - </Grid.RowDefinitions> - <TextBlock Margin="3.5" - VerticalAlignment="Center" - FontSize="18" - Foreground="DarkGreen" - Text="Glimpse Viewer" /> - <Button x:Name="btnContract" - Margin="7" - HorizontalAlignment="Right" - VerticalAlignment="Center" - Content="Contract" /> - <c:TabControl Grid.Row="1" - Width="690" - Height="390" - Background="Khaki" - SelectedIndex="2"> - <c:TabItem Header="Exceptions"> - <localc:ExceptionsViewer /> - </c:TabItem> - <c:TabItem Header="Bindings with no Source"> - <localc:BrokenBindingsViewer /> - </c:TabItem> - </c:TabControl> - </Grid> - </Grid> - -</UserControl>
--- a/SilverlightGlimpse/Controls/GlimpseViewer.xaml.cs Sat Apr 21 21:20:05 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -using System.Collections.Specialized; -using System.Windows; - -using SilverlightGlimpse.Models; -using SilverlightGlimpse.Services; - -namespace SilverlightGlimpse.Controls -{ - public partial class GlimpseViewer - { - public GlimpseViewer() - { - InitializeComponent(); - this.DataContext = GlimpseService.CreateInstance; - GlimpseService.CreateInstance.HostExceptions.CollectionChanged += HostExceptions_CollectionChanged; - } - - private void btnContract_Click(object sender, System.Windows.RoutedEventArgs e) - { - this.layoutViewer.Visibility = Visibility.Collapsed; - } - - private void btnExpand_Click(object sender, System.Windows.RoutedEventArgs e) - { - this.layoutViewer.Visibility = Visibility.Visible; - } - - private void HostExceptions_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) - { - int unhandledExceptionCount = 0; - int validationExceptionCount = 0; - - foreach (ExceptionWrapper ew in GlimpseService.CreateInstance.HostExceptions) - { - if (ew.IsValidationException) - validationExceptionCount++; - else - unhandledExceptionCount++; - } - - this.tbValidationExceptions.Text = validationExceptionCount.ToString(); - - this.elpValidationExceptions.Fill = validationExceptionCount == 0 - ? this.noExceptionsBrush - : this.hasExceptionsBrush; - - this.tbUnhandledExceptions.Text = unhandledExceptionCount.ToString(); - - this.elpUnhandledExceptions.Fill = unhandledExceptionCount == 0 - ? this.noExceptionsBrush - : this.hasExceptionsBrush; - } - } -} \ No newline at end of file
--- a/SilverlightGlimpse/Controls/LoadExceptionViewer.xaml Sat Apr 21 21:20:05 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -<UserControl x:Class="SilverlightGlimpse.Controls.LoadExceptionViewer" - xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> - <Border Width="700" - Height="375" - Margin="11" - Background="LightYellow" - BorderBrush="Red" - BorderThickness="2" - CornerRadius="20" - Padding="11"> - <Grid x:Name="LayoutRoot"> - <Grid.ColumnDefinitions> - <ColumnDefinition Width="200" /> - <ColumnDefinition Width="*" /> - </Grid.ColumnDefinitions> - <Grid.RowDefinitions> - <RowDefinition Height="Auto" /> - <RowDefinition Height="*" /> - </Grid.RowDefinitions> - <TextBlock Grid.ColumnSpan="2" - Margin="3.5" - VerticalAlignment="Center" - FontSize="18" - Foreground="Red" - Text="Exception Viewer" /> - - <ListBox x:Name="lbExceptions" - Grid.Row="1" - Margin="3.5" - DisplayMemberPath="Message" /> - - <TextBlock x:Name="txtSourceLocation" - Grid.ColumnSpan="2" - HorizontalAlignment="Right" - VerticalAlignment="Center" - FontSize="14" /> - <ScrollViewer Grid.Row="1" - Grid.Column="1" - Margin="3.5" - Background="White" - DataContext="{Binding ElementName=lbExceptions, - Path=SelectedItem}"> - <Grid> - <Grid.RowDefinitions> - <RowDefinition Height="Auto" /> - <RowDefinition Height="Auto" /> - <RowDefinition Height="Auto" /> - <RowDefinition Height="Auto" /> - <RowDefinition Height="Auto" /> - <RowDefinition Height="Auto" /> - </Grid.RowDefinitions> - <Rectangle Fill="BlanchedAlmond" /> - <TextBlock FontSize="14" - Text="Message" - TextDecorations="Underline" /> - <TextBlock Grid.Row="1" - FontSize="11" - Text="{Binding Path=Message}" - TextWrapping="Wrap" /> - - <Rectangle Grid.Row="2" Fill="BlanchedAlmond" /> - <TextBlock Grid.Row="2" - Margin="0,11,0,0" - FontSize="14" - Text="Stack Trace" - TextDecorations="Underline" /> - <TextBlock Grid.Row="3" - FontSize="11" - Text="{Binding Path=StackTrace}" - TextWrapping="Wrap" /> - - </Grid> - </ScrollViewer> - </Grid> - </Border> - -</UserControl> -
--- a/SilverlightGlimpse/Controls/LoadExceptionViewer.xaml.cs Sat Apr 21 21:20:05 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -using System; - -namespace SilverlightGlimpse.Controls -{ - public partial class LoadExceptionViewer - { - public LoadExceptionViewer() - { - InitializeComponent(); - } - - public LoadExceptionViewer(Exception e, string sourceLocation) - : this() - { - this.txtSourceLocation.Text = string.Concat("Source Location: ", sourceLocation); - - Exception ex = e; - - while (ex != null) - { - this.lbExceptions.Items.Add(ex); - ex = ex.InnerException; - } - - if (this.lbExceptions.Items.Count > 0) - { - this.lbExceptions.SelectedIndex = 0; - } - } - } -} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/FloatableWindow/FloatableWindow.cs Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,1698 @@ +// This source is subject to the Microsoft Public License (Ms-PL). +// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. +// All other rights reserved. + +using System.Collections; +using System.ComponentModel; +using System.Diagnostics; +using System.Windows.Automation; +using System.Windows.Automation.Peers; +using System.Windows.Controls.Primitives; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; + +namespace System.Windows.Controls +{ + /// <summary> + /// Provides a window that can be displayed over a parent window and blocks + /// interaction with the parent window. + /// </summary> + /// <QualityBand>Preview</QualityBand> + [TemplatePart(Name = PART_Chrome, Type = typeof(FrameworkElement))] + [TemplatePart(Name = PART_CloseButton, Type = typeof(ButtonBase))] + [TemplatePart(Name = PART_ContentPresenter, Type = typeof(FrameworkElement))] + [TemplatePart(Name = PART_ContentRoot, Type = typeof(FrameworkElement))] + [TemplatePart(Name = PART_Overlay, Type = typeof(Panel))] + [TemplatePart(Name = PART_Root, Type = typeof(FrameworkElement))] + [TemplatePart(Name = PART_Resizer, Type = typeof(FrameworkElement))] + [TemplateVisualState(Name = VSMSTATE_StateClosed, GroupName = VSMGROUP_Window)] + [TemplateVisualState(Name = VSMSTATE_StateOpen, GroupName = VSMGROUP_Window)] + public class FloatableWindow : ContentControl + { + #region Static Fields and Constants + + /// <summary> + /// The name of the Chrome template part. + /// </summary> + private const string PART_Chrome = "Chrome"; + + /// <summary> + /// The name of the Resizer template part. + /// </summary> + private const string PART_Resizer = "Resizer"; + + /// <summary> + /// The name of the CloseButton template part. + /// </summary> + private const string PART_CloseButton = "CloseButton"; + + /// <summary> + /// The name of the ContentPresenter template part. + /// </summary> + private const string PART_ContentPresenter = "ContentPresenter"; + + /// <summary> + /// The name of the ContentRoot template part. + /// </summary> + private const string PART_ContentRoot = "ContentRoot"; + + /// <summary> + /// The name of the Overlay template part. + /// </summary> + private const string PART_Overlay = "Overlay"; + + /// <summary> + /// The name of the Root template part. + /// </summary> + private const string PART_Root = "Root"; + + /// <summary> + /// The name of the WindowStates VSM group. + /// </summary> + private const string VSMGROUP_Window = "WindowStates"; + + /// <summary> + /// The name of the Closing VSM state. + /// </summary> + private const string VSMSTATE_StateClosed = "Closed"; + + /// <summary> + /// The name of the Opening VSM state. + /// </summary> + private const string VSMSTATE_StateOpen = "Open"; + + #region public bool HasCloseButton + + /// <summary> + /// Gets or sets a value indicating whether the + /// <see cref="T:System.Windows.Controls.FloatableWindow" /> has a close + /// button. + /// </summary> + /// <value> + /// True if the child window has a close button; otherwise, false. The + /// default is true. + /// </value> + public bool HasCloseButton + { + get { return (bool)GetValue(HasCloseButtonProperty); } + set { SetValue(HasCloseButtonProperty, value); } + } + + /// <summary> + /// Identifies the + /// <see cref="P:System.Windows.Controls.FloatableWindow.HasCloseButton" /> + /// dependency property. + /// </summary> + /// <value> + /// The identifier for the + /// <see cref="P:System.Windows.Controls.FloatableWindow.HasCloseButton" /> + /// dependency property. + /// </value> + public static readonly DependencyProperty HasCloseButtonProperty = + DependencyProperty.Register( + "HasCloseButton", + typeof(bool), + typeof(FloatableWindow), + new PropertyMetadata(true, OnHasCloseButtonPropertyChanged)); + + /// <summary> + /// HasCloseButtonProperty PropertyChangedCallback call back static function. + /// </summary> + /// <param name="d">FloatableWindow object whose HasCloseButton property is changed.</param> + /// <param name="e">DependencyPropertyChangedEventArgs which contains the old and new values.</param> + private static void OnHasCloseButtonPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + FloatableWindow cw = (FloatableWindow)d; + + if (cw.CloseButton != null) + { + if ((bool)e.NewValue) + { + cw.CloseButton.Visibility = Visibility.Visible; + } + else + { + cw.CloseButton.Visibility = Visibility.Collapsed; + } + } + } + + #endregion public bool HasCloseButton + + #region public Brush OverlayBrush + + /// <summary> + /// Gets or sets the visual brush that is used to cover the parent + /// window when the child window is open. + /// </summary> + /// <value> + /// The visual brush that is used to cover the parent window when the + /// <see cref="T:System.Windows.Controls.FloatableWindow" /> is open. The + /// default is null. + /// </value> + public Brush OverlayBrush + { + get { return (Brush)GetValue(OverlayBrushProperty); } + set { SetValue(OverlayBrushProperty, value); } + } + + /// <summary> + /// Identifies the + /// <see cref="P:System.Windows.Controls.FloatableWindow.OverlayBrush" /> + /// dependency property. + /// </summary> + /// <value> + /// The identifier for the + /// <see cref="P:System.Windows.Controls.FloatableWindow.OverlayBrush" /> + /// dependency property. + /// </value> + public static readonly DependencyProperty OverlayBrushProperty = + DependencyProperty.Register( + "OverlayBrush", + typeof(Brush), + typeof(FloatableWindow), + new PropertyMetadata(OnOverlayBrushPropertyChanged)); + + /// <summary> + /// OverlayBrushProperty PropertyChangedCallback call back static function. + /// </summary> + /// <param name="d">FloatableWindow object whose OverlayBrush property is changed.</param> + /// <param name="e">DependencyPropertyChangedEventArgs which contains the old and new values.</param> + private static void OnOverlayBrushPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + FloatableWindow cw = (FloatableWindow)d; + + if (cw.Overlay != null) + { + cw.Overlay.Background = (Brush)e.NewValue; + } + } + + #endregion public Brush OverlayBrush + + #region public double OverlayOpacity + + /// <summary> + /// Gets or sets the opacity of the overlay brush that is used to cover + /// the parent window when the child window is open. + /// </summary> + /// <value> + /// The opacity of the overlay brush that is used to cover the parent + /// window when the <see cref="T:System.Windows.Controls.FloatableWindow" /> + /// is open. The default is 1.0. + /// </value> + public double OverlayOpacity + { + get { return (double)GetValue(OverlayOpacityProperty); } + set { SetValue(OverlayOpacityProperty, value); } + } + + /// <summary> + /// Identifies the + /// <see cref="P:System.Windows.Controls.FloatableWindow.OverlayOpacity" /> + /// dependency property. + /// </summary> + /// <value> + /// The identifier for the + /// <see cref="P:System.Windows.Controls.FloatableWindow.OverlayOpacity" /> + /// dependency property. + /// </value> + public static readonly DependencyProperty OverlayOpacityProperty = + DependencyProperty.Register( + "OverlayOpacity", + typeof(double), + typeof(FloatableWindow), + new PropertyMetadata(OnOverlayOpacityPropertyChanged)); + + /// <summary> + /// OverlayOpacityProperty PropertyChangedCallback call back static function. + /// </summary> + /// <param name="d">FloatableWindow object whose OverlayOpacity property is changed.</param> + /// <param name="e">DependencyPropertyChangedEventArgs which contains the old and new values.</param> + private static void OnOverlayOpacityPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + FloatableWindow cw = (FloatableWindow)d; + + if (cw.Overlay != null) + { + cw.Overlay.Opacity = (double)e.NewValue; + } + } + + #endregion public double OverlayOpacity + + #region private static Control RootVisual + + /// <summary> + /// Gets the root visual element. + /// </summary> + private static Control RootVisual + { + get + { + return Application.Current == null ? null : (Application.Current.RootVisual as Control); + } + } + + #endregion private static Control RootVisual + + #region public object Title + + /// <summary> + /// Gets or sets the title that is displayed in the frame of the + /// <see cref="T:System.Windows.Controls.FloatableWindow" />. + /// </summary> + /// <value> + /// The title displayed at the top of the window. The default is null. + /// </value> + public object Title + { + get { return GetValue(TitleProperty); } + set { SetValue(TitleProperty, value); } + } + + /// <summary> + /// Identifies the + /// <see cref="P:System.Windows.Controls.FloatableWindow.Title" /> + /// dependency property. + /// </summary> + /// <value> + /// The identifier for the + /// <see cref="P:System.Windows.Controls.FloatableWindow.Title" /> + /// dependency property. + /// </value> + public static readonly DependencyProperty TitleProperty = + DependencyProperty.Register( + "Title", + typeof(object), + typeof(FloatableWindow), + null); + + #endregion public object Title + + #endregion Static Fields and Constants + + #region Member Fields + /// <summary> + /// Set in the overloaded Show method. Offsets the Popup vertically from the top left corner of the browser window by this amount. + /// </summary> + private double _verticalOffset; + + /// <summary> + /// Set in the overloaded Show method. Offsets the Popup horizontally from the top left corner of the browser window by this amount. + /// </summary> + private double _horizontalOffset; + + /// <summary> + /// Private accessor for the Resizer. + /// </summary> + private FrameworkElement _resizer; + + /// <summary> + /// Private accessor for the IsModal + /// </summary> + [DefaultValue(false)] + private bool _modal; + + /// <summary> + /// Private accessor for the Chrome. + /// </summary> + private FrameworkElement _chrome; + + /// <summary> + /// Private accessor for the click point on the chrome. + /// </summary> + private Point _clickPoint; + + /// <summary> + /// Private accessor for the Closing storyboard. + /// </summary> + private Storyboard _closed; + + /// <summary> + /// Private accessor for the ContentPresenter. + /// </summary> + private FrameworkElement _contentPresenter; + + /// <summary> + /// Private accessor for the translate transform that needs to be applied on to the ContentRoot. + /// </summary> + private TranslateTransform _contentRootTransform; + + /// <summary> + /// Content area desired width. + /// </summary> + private double _desiredContentWidth; + + /// <summary> + /// Content area desired height. + /// </summary> + private double _desiredContentHeight; + + /// <summary> + /// Desired margin for the window. + /// </summary> + private Thickness _desiredMargin; + + /// <summary> + /// Private accessor for the Dialog Result property. + /// </summary> + private bool? _dialogresult; + + /// <summary> + /// Private accessor for the FloatableWindow InteractionState. + /// </summary> + private WindowInteractionState _interactionState; + + /// <summary> + /// Boolean value that specifies whether the application is exit or not. + /// </summary> + private bool _isAppExit; + + /// <summary> + /// Boolean value that specifies whether the window is in closing state or not. + /// </summary> + private bool _isClosing; + + /// <summary> + /// Boolean value that specifies whether the window is opened. + /// </summary> + private bool _isOpen; + + /// <summary> + /// Private accessor for the Opening storyboard. + /// </summary> + private Storyboard _opened; + + /// <summary> + /// Boolean value that specifies whether the mouse is captured or not. + /// </summary> + private bool _isMouseCaptured; + + /// <summary> + /// Private accessor for the Root of the window. + /// </summary> + private FrameworkElement _root; + + /// <summary> + /// Private accessor for the position of the window with respect to RootVisual. + /// </summary> + private Point _windowPosition; + + private static int z; + + #endregion Member Fields + + #region Constructors + + /// <summary> + /// Initializes a new instance of the + /// <see cref="T:System.Windows.Controls.FloatableWindow" /> class. + /// </summary> + public FloatableWindow() + { + this.DefaultStyleKey = typeof(FloatableWindow); + this.InteractionState = WindowInteractionState.NotResponding; + this.ResizeMode = ResizeMode.CanResize; + } + + #endregion Constructors + + #region Events + + /// <summary> + /// Occurs when the <see cref="T:System.Windows.Controls.FloatableWindow" /> + /// is closed. + /// </summary> + public event EventHandler Closed; + + /// <summary> + /// Occurs when the <see cref="T:System.Windows.Controls.FloatableWindow" /> + /// is closing. + /// </summary> + public event EventHandler<CancelEventArgs> Closing; + + #endregion Events + + #region Properties + + public Panel ParentLayoutRoot + { + get; + set; + } + + /// <summary> + /// Gets the internal accessor for the ContentRoot of the window. + /// </summary> + internal FrameworkElement ContentRoot + { + get; + private set; + } + + /// <summary> + /// Setting for the horizontal positioning offset for start position + /// </summary> + public double HorizontalOffset + { + get { return _horizontalOffset; } + set { _horizontalOffset = value; } + } + + /// <summary> + /// Setting for the vertical positioning offset for start position + /// </summary> + public double VerticalOffset + { + get { return _verticalOffset; } + set { _verticalOffset = value; } + } + + /// <summary> + /// Gets the internal accessor for the modal of the window. + /// </summary> + public bool IsModal + { + get + { + return _modal; + } + } + + /// <summary> + /// Gets or sets a value indicating whether the + /// <see cref="T:System.Windows.Controls.FloatableWindow" /> was accepted or + /// canceled. + /// </summary> + /// <value> + /// True if the child window was accepted; false if the child window was + /// canceled. The default is null. + /// </value> + [TypeConverter(typeof(NullableBoolConverter))] + public bool? DialogResult + { + get + { + return this._dialogresult; + } + + set + { + if (this._dialogresult != value) + { + this._dialogresult = value; + this.Close(); + } + } + } + + /// <summary> + /// Gets the internal accessor for the PopUp of the window. + /// </summary> + internal Popup ChildWindowPopup + { + get; + private set; + } + + /// <summary> + /// Gets the internal accessor for the close button of the window. + /// </summary> + internal ButtonBase CloseButton + { + get; + private set; + } + + /// <summary> + /// Gets the InteractionState for the FloatableWindow. + /// </summary> + internal WindowInteractionState InteractionState + { + get + { + return this._interactionState; + } + private set + { + if (this._interactionState != value) + { + WindowInteractionState oldValue = this._interactionState; + this._interactionState = value; + FloatableWindowAutomationPeer peer = FloatableWindowAutomationPeer.FromElement(this) as FloatableWindowAutomationPeer; + + if (peer != null) + { + peer.RaiseInteractionStatePropertyChangedEvent(oldValue, this._interactionState); + } + } + } + } + + /// <summary> + /// Gets a value indicating whether the PopUp is open or not. + /// </summary> + private bool IsOpen + { + get + { + return (this.ChildWindowPopup != null && this.ChildWindowPopup.IsOpen) || + ((ParentLayoutRoot != null) && (ParentLayoutRoot.Children.Contains(this))); + } + } + + /// <summary> + /// Gets the internal accessor for the overlay of the window. + /// </summary> + internal Panel Overlay + { + get; + private set; + } + + public ResizeMode ResizeMode + { + get; + set; + } + + #endregion Properties + + #region Static Methods + + /// <summary> + /// Inverts the input matrix. + /// </summary> + /// <param name="matrix">The matrix values that is to be inverted.</param> + /// <returns>Returns a value indicating whether the inversion was successful or not.</returns> + private static bool InvertMatrix(ref Matrix matrix) + { + double determinant = (matrix.M11 * matrix.M22) - (matrix.M12 * matrix.M21); + + if (determinant == 0.0) + { + return false; + } + + Matrix matCopy = matrix; + matrix.M11 = matCopy.M22 / determinant; + matrix.M12 = -1 * matCopy.M12 / determinant; + matrix.M21 = -1 * matCopy.M21 / determinant; + matrix.M22 = matCopy.M11 / determinant; + matrix.OffsetX = ((matCopy.OffsetY * matCopy.M21) - (matCopy.OffsetX * matCopy.M22)) / determinant; + matrix.OffsetY = ((matCopy.OffsetX * matCopy.M12) - (matCopy.OffsetY * matCopy.M11)) / determinant; + + return true; + } + + #endregion Static Methods + + #region Methods + + /// <summary> + /// Executed when the application is exited. + /// </summary> + /// <param name="sender">The sender.</param> + /// <param name="e">Event args.</param> + internal void Application_Exit(object sender, EventArgs e) + { + if (this.IsOpen) + { + this._isAppExit = true; + try + { + this.Close(); + } + finally + { + this._isAppExit = false; + } + } + } + + /// <summary> + /// Executed when focus is given to the window via a click. Attempts to bring current + /// window to the front in the event there are more windows. + /// </summary> + internal void BringToFront() + { + z++; + Canvas.SetZIndex(this, z); +#if DEBUG + this.Title = z.ToString(); +#endif + } + + /// <summary> + /// Changes the visual state of the FloatableWindow. + /// </summary> + private void ChangeVisualState() + { + if (this._isClosing) + { + VisualStateManager.GoToState(this, VSMSTATE_StateClosed, true); + } + else + { + VisualStateManager.GoToState(this, VSMSTATE_StateOpen, true); + BringToFront(); + } + } + + /// <summary> + /// Executed when FloatableWindow size is changed. + /// </summary> + /// <param name="sender">Sender object.</param> + /// <param name="e">Size changed event args.</param> + private void ChildWindow_SizeChanged(object sender, SizeChangedEventArgs e) + { + if (_modal) + { + if (this.Overlay != null) + { + if (e.NewSize.Height != this.Overlay.Height) + { + this._desiredContentHeight = e.NewSize.Height; + } + + if (e.NewSize.Width != this.Overlay.Width) + { + this._desiredContentWidth = e.NewSize.Width; + } + } + + if (this.IsOpen) + { + this.UpdateOverlaySize(); + } + } + } + + /// <summary> + /// Closes a <see cref="T:System.Windows.Controls.FloatableWindow" />. + /// </summary> + public void Close() + { + // AutomationPeer returns "Closing" when Close() is called + // but the window is not closed completely: + this.InteractionState = WindowInteractionState.Closing; + CancelEventArgs e = new CancelEventArgs(); + this.OnClosing(e); + + // On ApplicationExit, close() cannot be cancelled + if (!e.Cancel || this._isAppExit) + { + if (RootVisual != null) + { + RootVisual.IsEnabled = true; + } + + // Close Popup + if (this.IsOpen) + { + if (this._closed != null) + { + // Popup will be closed when the storyboard ends + this._isClosing = true; + try + { + var sb = GetVisualStateStoryboard("WindowStates", "Closed"); + sb.Completed += (s, args) => + { + this.ParentLayoutRoot.Children.Remove(this); + this.OnClosed(EventArgs.Empty); + this.UnSubscribeFromEvents(); + this.UnsubscribeFromTemplatePartEvents(); + + if (Application.Current.RootVisual != null) + { + Application.Current.RootVisual.GotFocus -= new RoutedEventHandler(this.RootVisual_GotFocus); + } + }; + this.ChangeVisualState(); + } + finally + { + this._isClosing = false; + } + } + else + { + // If no closing storyboard is defined, close the Popup + this.ChildWindowPopup.IsOpen = false; + } + + if (!this._dialogresult.HasValue) + { + // If close action is not happening because of DialogResult property change action, + // Dialogresult is always false: + this._dialogresult = false; + } + + //this.OnClosed(EventArgs.Empty); + //this.UnSubscribeFromEvents(); + //this.UnsubscribeFromTemplatePartEvents(); + + //if (Application.Current.RootVisual != null) + //{ + // Application.Current.RootVisual.GotFocus -= new RoutedEventHandler(this.RootVisual_GotFocus); + //} + } + } + else + { + // If the Close is cancelled, DialogResult should always be NULL: + this._dialogresult = null; + this.InteractionState = WindowInteractionState.Running; + } + } + + /// <summary> + /// Brings the window to the front of others + /// </summary> + /// <param name="sender"></param> + /// <param name="e"></param> + internal void ContentRoot_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + BringToFront(); + } + + /// <summary> + /// Executed when the CloseButton is clicked. + /// </summary> + /// <param name="sender">Sender object.</param> + /// <param name="e">Routed event args.</param> + internal void CloseButton_Click(object sender, RoutedEventArgs e) + { + this.Close(); + } + + /// <summary> + /// Executed when the Closing storyboard ends. + /// </summary> + /// <param name="sender">Sender object.</param> + /// <param name="e">Event args.</param> + private void Closing_Completed(object sender, EventArgs e) + { + if (this.ChildWindowPopup != null) + { + this.ChildWindowPopup.IsOpen = false; + } + + // AutomationPeer returns "NotResponding" when the FloatableWindow is closed: + this.InteractionState = WindowInteractionState.NotResponding; + + if (this._closed != null) + { + this._closed.Completed -= new EventHandler(this.Closing_Completed); + } + } + + /// <summary> + /// Executed when the a key is presses when the window is open. + /// </summary> + /// <param name="sender">Sender object.</param> + /// <param name="e">Key event args.</param> + private void ChildWindow_KeyDown(object sender, KeyEventArgs e) + { + FloatableWindow ew = sender as FloatableWindow; + Debug.Assert(ew != null, "FloatableWindow instance is null."); + + // Ctrl+Shift+F4 closes the FloatableWindow + if (e != null && !e.Handled && e.Key == Key.F4 && + ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) && + ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)) + { + ew.Close(); + e.Handled = true; + } + } + + /// <summary> + /// Executed when the window loses focus. + /// </summary> + /// <param name="sender">Sender object.</param> + /// <param name="e">Routed event args.</param> + private void ChildWindow_LostFocus(object sender, RoutedEventArgs e) + { + // If the FloatableWindow loses focus but the popup is still open, + // it means another popup is opened. To get the focus back when the + // popup is closed, we handle GotFocus on the RootVisual + // TODO: Something else could get focus and handle the GotFocus event right. + // Try listening to routed events that were Handled (new SL 3 feature) + // Blocked by Jolt bug #29419 + if (this.IsOpen && Application.Current != null && Application.Current.RootVisual != null) + { + this.InteractionState = WindowInteractionState.BlockedByModalWindow; + Application.Current.RootVisual.GotFocus += new RoutedEventHandler(this.RootVisual_GotFocus); + } + } + + /// <summary> + /// Executed when mouse left button is down on the chrome. + /// </summary> + /// <param name="sender">Sender object.</param> + /// <param name="e">Mouse button event args.</param> + private void Chrome_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + if (this._chrome != null) + { + e.Handled = true; + + if (this.CloseButton != null && !this.CloseButton.IsTabStop) + { + this.CloseButton.IsTabStop = true; + try + { + this.Focus(); + } + finally + { + this.CloseButton.IsTabStop = false; + } + } + else + { + this.Focus(); + } + this._chrome.CaptureMouse(); + this._isMouseCaptured = true; + this._clickPoint = e.GetPosition(sender as UIElement); +#if DEBUG + this.Title = string.Format("X:{0},Y:{1}", this._clickPoint.X.ToString(), this._clickPoint.Y.ToString()); +#endif + } + } + + /// <summary> + /// Executed when mouse left button is up on the chrome. + /// </summary> + /// <param name="sender">Sender object.</param> + /// <param name="e">Mouse button event args.</param> + private void Chrome_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + if (this._chrome != null) + { + //e.Handled = true; + this._chrome.ReleaseMouseCapture(); + this._isMouseCaptured = false; + } + } + + /// <summary> + /// Executed when mouse moves on the chrome. + /// </summary> + /// <param name="sender">Sender object.</param> + /// <param name="e">Mouse event args.</param> + private void Chrome_MouseMove(object sender, MouseEventArgs e) + { + #region New ChildWindow Code not working + //if (this._isMouseCaptured && this.ContentRoot != null && Application.Current != null && Application.Current.RootVisual != null) + //{ + // Point position = e.GetPosition(Application.Current.RootVisual); + + // GeneralTransform gt = this.ContentRoot.TransformToVisual(Application.Current.RootVisual); + + // if (gt != null) + // { + // Point p = gt.Transform(this._clickPoint); + // this._windowPosition = gt.Transform(new Point(0, 0)); + + // if (position.X < 0) + // { + // double Y = FindPositionY(p, position, 0); + // position = new Point(0, Y); + // } + + // if (position.X > this.Width) + // { + // double Y = FindPositionY(p, position, this.Width); + // position = new Point(this.Width, Y); + // } + + // if (position.Y < 0) + // { + // double X = FindPositionX(p, position, 0); + // position = new Point(X, 0); + // } + + // if (position.Y > this.Height) + // { + // double X = FindPositionX(p, position, this.Height); + // position = new Point(X, this.Height); + // } + + // double x = position.X - p.X; + // double y = position.Y - p.Y; + // UpdateContentRootTransform(x, y); + // } + //} + #endregion + if (this._isMouseCaptured && this.ContentRoot != null) + { + // If the child window is dragged out of the page, return + if (Application.Current != null && Application.Current.RootVisual != null && + (e.GetPosition(Application.Current.RootVisual).X < 0 || e.GetPosition(Application.Current.RootVisual).Y < 0)) + { + return; + } + + TransformGroup transformGroup = this.ContentRoot.RenderTransform as TransformGroup; + + if (transformGroup == null) + { + transformGroup = new TransformGroup(); + transformGroup.Children.Add(this.ContentRoot.RenderTransform); + } + + TranslateTransform t = new TranslateTransform(); + t.X = e.GetPosition(this.ContentRoot).X - this._clickPoint.X; + t.Y = e.GetPosition(this.ContentRoot).Y - this._clickPoint.Y; + if (transformGroup != null) + { + transformGroup.Children.Add(t); + this.ContentRoot.RenderTransform = transformGroup; + } + } + } + + /// <summary> + /// Executed when the ContentPresenter size changes. + /// </summary> + /// <param name="sender">Content Presenter object.</param> + /// <param name="e">SizeChanged event args.</param> + private void ContentPresenter_SizeChanged(object sender, SizeChangedEventArgs e) + { + // timheuer: not sure really why this is here? + //if (this.ContentRoot != null && Application.Current != null && Application.Current.RootVisual != null && _isOpen) + //{ + // GeneralTransform gt = this.ContentRoot.TransformToVisual(Application.Current.RootVisual); + + // if (gt != null) + // { + // Point p = gt.Transform(new Point(0, 0)); + + // double x = this._windowPosition.X - p.X; + // double y = this._windowPosition.Y - p.Y; + // UpdateContentRootTransform(x, y); + // } + //} + + //RectangleGeometry rg = new RectangleGeometry(); + //rg.Rect = new Rect(0, 0, this._contentPresenter.ActualWidth, this._contentPresenter.ActualHeight); + //this._contentPresenter.Clip = rg; + //this.UpdatePosition(); + } + + /// <summary> + /// Finds the X coordinate of a point that is defined by a line. + /// </summary> + /// <param name="p1">Starting point of the line.</param> + /// <param name="p2">Ending point of the line.</param> + /// <param name="y">Y coordinate of the point.</param> + /// <returns>X coordinate of the point.</returns> + private static double FindPositionX(Point p1, Point p2, double y) + { + if (y == p1.Y || p1.X == p2.X) + { + return p2.X; + } + + Debug.Assert(p1.Y != p2.Y, "Unexpected equal Y coordinates"); + + return (((y - p1.Y) * (p1.X - p2.X)) / (p1.Y - p2.Y)) + p1.X; + } + + /// <summary> + /// Finds the Y coordinate of a point that is defined by a line. + /// </summary> + /// <param name="p1">Starting point of the line.</param> + /// <param name="p2">Ending point of the line.</param> + /// <param name="x">X coordinate of the point.</param> + /// <returns>Y coordinate of the point.</returns> + private static double FindPositionY(Point p1, Point p2, double x) + { + if (p1.Y == p2.Y || x == p1.X) + { + return p2.Y; + } + + Debug.Assert(p1.X != p2.X, "Unexpected equal X coordinates"); + + return (((p1.Y - p2.Y) * (x - p1.X)) / (p1.X - p2.X)) + p1.Y; + } + + /// <summary> + /// Builds the visual tree for the + /// <see cref="T:System.Windows.Controls.FloatableWindow" /> control when a + /// new template is applied. + /// </summary> + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "No need to split the code into two parts.")] + public override void OnApplyTemplate() + { + this.UnsubscribeFromTemplatePartEvents(); + + base.OnApplyTemplate(); + + this.CloseButton = GetTemplateChild(PART_CloseButton) as ButtonBase; + + if (this.CloseButton != null) + { + if (this.HasCloseButton) + { + this.CloseButton.Visibility = Visibility.Visible; + } + else + { + this.CloseButton.Visibility = Visibility.Collapsed; + } + } + + if (this._closed != null) + { + this._closed.Completed -= new EventHandler(this.Closing_Completed); + } + + if (this._opened != null) + { + this._opened.Completed -= new EventHandler(this.Opening_Completed); + } + + this._root = GetTemplateChild(PART_Root) as FrameworkElement; + this._resizer = GetTemplateChild(PART_Resizer) as FrameworkElement; + + if (this._root != null) + { + IList groups = VisualStateManager.GetVisualStateGroups(this._root); + + if (groups != null) + { + IList states = null; + + foreach (VisualStateGroup vsg in groups) + { + if (vsg.Name == FloatableWindow.VSMGROUP_Window) + { + states = vsg.States; + break; + } + } + + if (states != null) + { + foreach (VisualState state in states) + { + if (state.Name == FloatableWindow.VSMSTATE_StateClosed) + { + this._closed = state.Storyboard; + } + + if (state.Name == FloatableWindow.VSMSTATE_StateOpen) + { + this._opened = state.Storyboard; + } + } + } + } + //TODO: Figure out why I can't wire up the event below in SubscribeToTemplatePartEvents + this._root.MouseLeftButtonDown += new MouseButtonEventHandler(this.ContentRoot_MouseLeftButtonDown); + + if (this.ResizeMode == ResizeMode.CanResize) + { + this._resizer.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(Resizer_MouseLeftButtonDown); + this._resizer.MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(Resizer_MouseLeftButtonUp); + this._resizer.MouseMove += new System.Windows.Input.MouseEventHandler(Resizer_MouseMove); + this._resizer.MouseEnter += new MouseEventHandler(Resizer_MouseEnter); + this._resizer.MouseLeave += new MouseEventHandler(Resizer_MouseLeave); + } + else + { + this._resizer.Opacity = 0; + } + } + + this.ContentRoot = GetTemplateChild(PART_ContentRoot) as FrameworkElement; + + this._chrome = GetTemplateChild(PART_Chrome) as FrameworkElement; + + this.Overlay = GetTemplateChild(PART_Overlay) as Panel; + + this._contentPresenter = GetTemplateChild(PART_ContentPresenter) as FrameworkElement; + + this.SubscribeToTemplatePartEvents(); + this.SubscribeToStoryBoardEvents(); + this._desiredMargin = this.Margin; + this.Margin = new Thickness(0); + + // Update overlay size + if (this.IsOpen && (this.ChildWindowPopup != null)) + { + this._desiredContentHeight = this.Height; + this._desiredContentWidth = this.Width; + this.UpdateOverlaySize(); + this.UpdateRenderTransform(); + this.ChangeVisualState(); + } + } + + void Resizer_MouseLeave(object sender, MouseEventArgs e) + { + if (!this._isMouseCaptured) + { + this._resizer.Opacity = .25; + } + } + + void Resizer_MouseEnter(object sender, MouseEventArgs e) + { + if (!this._isMouseCaptured) + { + this._resizer.Opacity = 1; + } + } + + /// <summary> + /// Raises the + /// <see cref="E:System.Windows.Controls.FloatableWindow.Closed" /> event. + /// </summary> + /// <param name="e">The event data.</param> + protected virtual void OnClosed(EventArgs e) + { + EventHandler handler = this.Closed; + + if (null != handler) + { + handler(this, e); + } + + this._isOpen = false; + if (!_modal) + { + this.ParentLayoutRoot.Children.Remove(this); + } + } + + /// <summary> + /// Raises the + /// <see cref="E:System.Windows.Controls.FloatableWindow.Closing" /> event. + /// </summary> + /// <param name="e">The event data.</param> + protected virtual void OnClosing(CancelEventArgs e) + { + EventHandler<CancelEventArgs> handler = this.Closing; + + if (null != handler) + { + handler(this, e); + } + } + + /// <summary> + /// Returns a + /// <see cref="T:System.Windows.Automation.Peers.FloatableWindowAutomationPeer" /> + /// for use by the Silverlight automation infrastructure. + /// </summary> + /// <returns> + /// <see cref="T:System.Windows.Automation.Peers.FloatableWindowAutomationPeer" /> + /// for the <see cref="T:System.Windows.Controls.FloatableWindow" /> object. + /// </returns> + protected override AutomationPeer OnCreateAutomationPeer() + { + return new FloatableWindowAutomationPeer(this); + } + + /// <summary> + /// This method is called every time a + /// <see cref="T:System.Windows.Controls.FloatableWindow" /> is displayed. + /// </summary> + protected virtual void OnOpened() + { + this.UpdatePosition(); + this._isOpen = true; + + if (this.Overlay != null) + { + this.Overlay.Opacity = this.OverlayOpacity; + this.Overlay.Background = this.OverlayBrush; + } + + if (!this.Focus()) + { + // If the Focus() fails it means there is no focusable element in the + // FloatableWindow. In this case we set IsTabStop to true to have the keyboard functionality + this.IsTabStop = true; + this.Focus(); + } + } + + /// <summary> + /// Executed when the opening storyboard finishes. + /// </summary> + /// <param name="sender">Sender object.</param> + /// <param name="e">Event args.</param> + private void Opening_Completed(object sender, EventArgs e) + { + if (this._opened != null) + { + this._opened.Completed -= new EventHandler(this.Opening_Completed); + } + // AutomationPeer returns "ReadyForUserInteraction" when the FloatableWindow + // is open and all animations have been completed. + this.InteractionState = WindowInteractionState.ReadyForUserInteraction; + this.OnOpened(); + } + + /// <summary> + /// Executed when the page resizes. + /// </summary> + /// <param name="sender">Sender object.</param> + /// <param name="e">Event args.</param> + private void Page_Resized(object sender, EventArgs e) + { + if (this.ChildWindowPopup != null) + { + this.UpdateOverlaySize(); + } + } + + /// <summary> + /// Executed when the root visual gets focus. + /// </summary> + /// <param name="sender">Sender object.</param> + /// <param name="e">Routed event args.</param> + private void RootVisual_GotFocus(object sender, RoutedEventArgs e) + { + this.Focus(); + this.InteractionState = WindowInteractionState.ReadyForUserInteraction; + } + + public void Show() + { + ShowWindow(false); + } + + public void ShowDialog() + { + _verticalOffset = 0; + _horizontalOffset = 0; + ShowWindow(true); + } + + public void Show(double horizontalOffset, double verticalOffset) + { + _horizontalOffset = horizontalOffset; + _verticalOffset = verticalOffset; + ShowWindow(false); + } + + /// <summary> + /// Opens a <see cref="T:System.Windows.Controls.FloatableWindow" /> and + /// returns without waiting for the + /// <see cref="T:System.Windows.Controls.FloatableWindow" /> to close. + /// </summary> + /// <exception cref="T:System.InvalidOperationException"> + /// The child window is already in the visual tree. + /// </exception> + internal void ShowWindow(bool isModal) + { + _modal = isModal; + + // AutomationPeer returns "Running" when Show() is called + // but the FloatableWindow is not ready for user interaction: + this.InteractionState = WindowInteractionState.Running; + + this.SubscribeToEvents(); + this.SubscribeToTemplatePartEvents(); + this.SubscribeToStoryBoardEvents(); + + + // MaxHeight and MinHeight properties should not be overwritten: + this.MaxHeight = double.PositiveInfinity; + this.MaxWidth = double.PositiveInfinity; + + if (_modal) + { + if (this.ChildWindowPopup == null) + { + this.ChildWindowPopup = new Popup(); + + try + { + this.ChildWindowPopup.Child = this; + } + catch (ArgumentException) + { + // If the FloatableWindow is already in the visualtree, we cannot set it to be the child of the popup + // we are throwing a friendlier exception for this case: + this.InteractionState = WindowInteractionState.NotResponding; + throw new InvalidOperationException(Properties.Resources.ChildWindow_InvalidOperation); + } + } + + if (this.ChildWindowPopup != null && Application.Current.RootVisual != null) + { + this.ChildWindowPopup.IsOpen = true; + + this.ChildWindowPopup.HorizontalOffset = _horizontalOffset; + this.ChildWindowPopup.VerticalOffset = _verticalOffset; + + // while the FloatableWindow is open, the DialogResult is always NULL: + this._dialogresult = null; + } + } + else + { + if (ParentLayoutRoot != null) + { + this.SetValue(Canvas.TopProperty, _verticalOffset); + this.SetValue(Canvas.LeftProperty, _horizontalOffset); + this.ParentLayoutRoot.Children.Add(this); + this.BringToFront(); + } + else + { + throw new ArgumentNullException("ParentLayoutRoot", "You need to specify a root Panel element to add the window elements to."); + } + } + + // disable the underlying UI + if (RootVisual != null && _modal) + { + RootVisual.IsEnabled = false; + } + + // if the template is already loaded, display loading visuals animation + if (this.ContentRoot == null) + { + this.Loaded += (s, args) => + { + if (this.ContentRoot != null) + { + this.ChangeVisualState(); + } + }; + } + else + { + this.ChangeVisualState(); + } + } + + /// <summary> + /// Subscribes to events when the FloatableWindow is opened. + /// </summary> + private void SubscribeToEvents() + { + if (Application.Current != null && Application.Current.Host != null && Application.Current.Host.Content != null) + { + Application.Current.Exit += new EventHandler(this.Application_Exit); + Application.Current.Host.Content.Resized += new EventHandler(this.Page_Resized); + } + + this.KeyDown += new KeyEventHandler(this.ChildWindow_KeyDown); + if (_modal) + { + this.LostFocus += new RoutedEventHandler(this.ChildWindow_LostFocus); + } + this.SizeChanged += new SizeChangedEventHandler(this.ChildWindow_SizeChanged); + } + + /// <summary> + /// Subscribes to events that are on the storyboards. + /// Unsubscribing from these events happen in the event handlers individually. + /// </summary> + private void SubscribeToStoryBoardEvents() + { + if (this._closed != null) + { + this._closed.Completed += new EventHandler(this.Closing_Completed); + } + + if (this._opened != null) + { + this._opened.Completed += new EventHandler(this.Opening_Completed); + } + } + + /// <summary> + /// Subscribes to events on the template parts. + /// </summary> + private void SubscribeToTemplatePartEvents() + { + if (this.CloseButton != null) + { + this.CloseButton.Click += new RoutedEventHandler(this.CloseButton_Click); + } + + if (this._chrome != null) + { + this._chrome.MouseLeftButtonDown += new MouseButtonEventHandler(this.Chrome_MouseLeftButtonDown); + this._chrome.MouseLeftButtonUp += new MouseButtonEventHandler(this.Chrome_MouseLeftButtonUp); + this._chrome.MouseMove += new MouseEventHandler(this.Chrome_MouseMove); + } + + if (this._contentPresenter != null) + { + this._contentPresenter.SizeChanged += new SizeChangedEventHandler(this.ContentPresenter_SizeChanged); + } + } + + /// <summary> + /// Unsubscribe from events when the FloatableWindow is closed. + /// </summary> + private void UnSubscribeFromEvents() + { + if (Application.Current != null && Application.Current.Host != null && Application.Current.Host.Content != null) + { + Application.Current.Exit -= new EventHandler(this.Application_Exit); + Application.Current.Host.Content.Resized -= new EventHandler(this.Page_Resized); + } + + this.KeyDown -= new KeyEventHandler(this.ChildWindow_KeyDown); + if (_modal) + { + this.LostFocus -= new RoutedEventHandler(this.ChildWindow_LostFocus); + } + this.SizeChanged -= new SizeChangedEventHandler(this.ChildWindow_SizeChanged); + } + + /// <summary> + /// Unsubscribe from the events that are subscribed on the template part elements. + /// </summary> + private void UnsubscribeFromTemplatePartEvents() + { + if (this.CloseButton != null) + { + this.CloseButton.Click -= new RoutedEventHandler(this.CloseButton_Click); + } + + if (this._chrome != null) + { + this._chrome.MouseLeftButtonDown -= new MouseButtonEventHandler(this.Chrome_MouseLeftButtonDown); + this._chrome.MouseLeftButtonUp -= new MouseButtonEventHandler(this.Chrome_MouseLeftButtonUp); + this._chrome.MouseMove -= new MouseEventHandler(this.Chrome_MouseMove); + } + + if (this._contentPresenter != null) + { + this._contentPresenter.SizeChanged -= new SizeChangedEventHandler(this.ContentPresenter_SizeChanged); + } + } + + /// <summary> + /// Updates the size of the overlay of the window. + /// </summary> + private void UpdateOverlaySize() + { + if (_modal) + { + if (this.Overlay != null && Application.Current != null && Application.Current.Host != null && Application.Current.Host.Content != null) + { + this.Height = Application.Current.Host.Content.ActualHeight; + this.Width = Application.Current.Host.Content.ActualWidth; + this.Overlay.Height = this.Height; + this.Overlay.Width = this.Width; + + if (this.ContentRoot != null) + { + this.ContentRoot.Width = this._desiredContentWidth; + this.ContentRoot.Height = this._desiredContentHeight; + this.ContentRoot.Margin = this._desiredMargin; + } + } + } + else + { + if (this.Overlay != null) + { + this.Overlay.Visibility = Visibility.Collapsed; + } + } + } + + /// <summary> + /// Updates the position of the window in case the size of the content changes. + /// This allows FloatableWindow only scale from right and bottom. + /// </summary> + private void UpdatePosition() + { + if (this.ContentRoot != null && Application.Current != null && Application.Current.RootVisual != null) + { + GeneralTransform gt = this.ContentRoot.TransformToVisual(Application.Current.RootVisual); + + if (gt != null) + { + this._windowPosition = gt.Transform(new Point(0, 0)); + } + } + } + + /// <summary> + /// Updates the render transform applied on the overlay. + /// </summary> + private void UpdateRenderTransform() + { + if (this._root != null && this.ContentRoot != null) + { + // The Overlay part should not be affected by the render transform applied on the + // FloatableWindow. In order to achieve this, we adjust an identity matrix to represent + // the _root's transformation, invert it, apply the inverted matrix on the _root, so that + // nothing is affected by the rendertransform, and apply the original transform only on the Content + GeneralTransform gt = this._root.TransformToVisual(null); + if (gt != null) + { + Point p10 = new Point(1, 0); + Point p01 = new Point(0, 1); + Point transform10 = gt.Transform(p10); + Point transform01 = gt.Transform(p01); + + Matrix transformToRootMatrix = Matrix.Identity; + transformToRootMatrix.M11 = transform10.X; + transformToRootMatrix.M12 = transform10.Y; + transformToRootMatrix.M21 = transform01.X; + transformToRootMatrix.M22 = transform01.Y; + + MatrixTransform original = new MatrixTransform(); + original.Matrix = transformToRootMatrix; + + InvertMatrix(ref transformToRootMatrix); + MatrixTransform mt = new MatrixTransform(); + mt.Matrix = transformToRootMatrix; + + TransformGroup tg = this._root.RenderTransform as TransformGroup; + + if (tg != null) + { + tg.Children.Add(mt); + } + else + { + this._root.RenderTransform = mt; + } + + tg = this.ContentRoot.RenderTransform as TransformGroup; + + if (tg != null) + { + tg.Children.Add(original); + } + else + { + this.ContentRoot.RenderTransform = original; + } + } + } + } + + /// <summary> + /// Updates the ContentRootTranslateTransform. + /// </summary> + /// <param name="X">X coordinate of the transform.</param> + /// <param name="Y">Y coordinate of the transform.</param> + private void UpdateContentRootTransform(double X, double Y) + { + if (this._contentRootTransform == null) + { + this._contentRootTransform = new TranslateTransform(); + this._contentRootTransform.X = X; + this._contentRootTransform.Y = Y; + + TransformGroup transformGroup = this.ContentRoot.RenderTransform as TransformGroup; + + if (transformGroup == null) + { + transformGroup = new TransformGroup(); + transformGroup.Children.Add(this.ContentRoot.RenderTransform); + } + transformGroup.Children.Add(this._contentRootTransform); + this.ContentRoot.RenderTransform = transformGroup; + } + else + { + this._contentRootTransform.X += X; + this._contentRootTransform.Y += Y; + } + } + + private void Resizer_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) + { + this._resizer.CaptureMouse(); + this._isMouseCaptured = true; + this._clickPoint = e.GetPosition(sender as UIElement); + +#if DEBUG + this.Title = string.Format("X:{0},Y:{1}", this._clickPoint.X.ToString(), this._clickPoint.Y.ToString()); +#endif + } + + private void Resizer_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e) + { + this._resizer.ReleaseMouseCapture(); + this._isMouseCaptured = false; + this._resizer.Opacity = 0.25; + } + + private void Resizer_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) + { + if (this._isMouseCaptured && this.ContentRoot != null) + { + // If the child window is dragged out of the page, return + if (Application.Current != null && Application.Current.RootVisual != null && + (e.GetPosition(Application.Current.RootVisual).X < 0 || e.GetPosition(Application.Current.RootVisual).Y < 0)) + { + return; + } + +#if DEBUG + this.Title = string.Format("X:{0},Y:{1}", this._clickPoint.X.ToString(), this._clickPoint.Y.ToString()); +#endif + + Point p = e.GetPosition(this.ContentRoot); + + if ((p.X > this._clickPoint.X) && (p.Y > this._clickPoint.Y)) + { + this.Width = (double)(p.X - (12 - this._clickPoint.X)); + this.Height = (double)(p.Y - (12 - this._clickPoint.Y)); + } + } + } + + private Storyboard GetVisualStateStoryboard(string visualStateGroupName, string visualStateName) + { + foreach (VisualStateGroup g in VisualStateManager.GetVisualStateGroups((FrameworkElement)this.ContentRoot.Parent)) + { + if (g.Name != visualStateGroupName) continue; + foreach (VisualState s in g.States) + { + if (s.Name != visualStateName) continue; + return s.Storyboard; + } + } + return null; + } + + #endregion Methods + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/FloatableWindow/FloatableWindow.csproj Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,112 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup Condition="'$(MSBuildToolsVersion)' == '3.5'"> + <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> + </PropertyGroup> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProductVersion>9.0.30729</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{D47E6045-91BB-4CD0-942F-FF015F10F7F2}</ProjectGuid> + <ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>FloatableWindow</RootNamespace> + <AssemblyName>FloatableWindow</AssemblyName> + <TargetFrameworkVersion>v3.0</TargetFrameworkVersion> + <SilverlightApplication>false</SilverlightApplication> + <ValidateXaml>true</ValidateXaml> + <ThrowErrorsInValidation>true</ThrowErrorsInValidation> + <SignAssembly>true</SignAssembly> + <AssemblyOriginatorKeyFile>FloatableWindowStrongNameKey.snk</AssemblyOriginatorKeyFile> + <SccProjectName> + </SccProjectName> + <SccLocalPath> + </SccLocalPath> + <SccAuxPath> + </SccAuxPath> + <SccProvider> + </SccProvider> + <TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier> + <SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion> + <FileUpgradeFlags> + </FileUpgradeFlags> + <UpgradeBackupLocation> + </UpgradeBackupLocation> + <OldToolsVersion>3.5</OldToolsVersion> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>Bin\Debug</OutputPath> + <DefineConstants>DEBUG;TRACE;SILVERLIGHT</DefineConstants> + <NoStdLib>true</NoStdLib> + <NoConfig>true</NoConfig> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <RunCodeAnalysis>true</RunCodeAnalysis> + <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>Bin\Release</OutputPath> + <DefineConstants>TRACE;SILVERLIGHT</DefineConstants> + <NoStdLib>true</NoStdLib> + <NoConfig>true</NoConfig> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> + </PropertyGroup> + <ItemGroup> + <Reference Include="System.Windows" /> + <Reference Include="mscorlib" /> + <Reference Include="system" /> + <Reference Include="System.Core" /> + <Reference Include="System.Xml" /> + <Reference Include="System.Net" /> + <Reference Include="System.Windows.Browser" /> + </ItemGroup> + <ItemGroup> + <Compile Include="FloatableWindow.cs" /> + <Compile Include="FloatableWindowAutomationPeer.cs" /> + <Compile Include="GlobalSuppressions.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="Properties\Resources.Designer.cs" /> + <Compile Include="ResizeMode.cs" /> + </ItemGroup> + <ItemGroup> + <Page Include="themes\generic.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:MarkupCompilePass1</Generator> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </Page> + </ItemGroup> + <ItemGroup> + <Content Include="README.txt" /> + </ItemGroup> + <ItemGroup> + <None Include="FloatableWindowStrongNameKey.snk" /> + </ItemGroup> + <ItemGroup> + <EmbeddedResource Include="Properties\Resources.resx" /> + </ItemGroup> + <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> + <ProjectExtensions> + <VisualStudio> + <FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}"> + <SilverlightProjectProperties /> + </FlavorProperties> + </VisualStudio> + </ProjectExtensions> +</Project> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/FloatableWindow/FloatableWindow.sln Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FloatableWindow", "FloatableWindow.csproj", "{D47E6045-91BB-4CD0-942F-FF015F10F7F2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D47E6045-91BB-4CD0-942F-FF015F10F7F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D47E6045-91BB-4CD0-942F-FF015F10F7F2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D47E6045-91BB-4CD0-942F-FF015F10F7F2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D47E6045-91BB-4CD0-942F-FF015F10F7F2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/FloatableWindow/FloatableWindowAutomationPeer.cs Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,429 @@ +// (c) Copyright Microsoft Corporation. +// This source is subject to the Microsoft Public License (Ms-PL). +// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. +// All other rights reserved. + +using System.Windows.Automation.Provider; +using System.Windows.Controls; +using System.Windows.Media; + +namespace System.Windows.Automation.Peers +{ + /// <summary> + /// Exposes <see cref="T:System.Windows.Controls.FloatableWindow" /> types to UI + /// automation. + /// </summary> + /// <QualityBand>Preview</QualityBand> + public class FloatableWindowAutomationPeer : FrameworkElementAutomationPeer, IWindowProvider, ITransformProvider + { + #region Data + + /// <summary> + /// Specifies whether the FloatableWindow is the top most element. + /// </summary> + private bool _isTopMost; + + #endregion Data + + #region Properties + + /// <summary> + /// Gets or sets a value indicating whether the FloatableWindow is the top most element. + /// </summary> + private bool IsTopMostPrivate + { + get + { + return this._isTopMost; + } + set + { + if (this._isTopMost != value) + { + this._isTopMost = value; + this.RaisePropertyChangedEvent(WindowPatternIdentifiers.IsTopmostProperty, !this._isTopMost, this._isTopMost); + } + } + } + + /// <summary> + /// Gets the owning FloatableWindow. + /// </summary> + private FloatableWindow OwningFloatableWindow + { + get + { + return (FloatableWindow)Owner; + } + } + + #endregion Properties + + /// <summary> + /// Initializes a new instance of the + /// <see cref="T:System.Windows.Automation.Peers.FloatableWindowAutomationPeer" /> + /// class. + /// </summary> + /// <param name="owner"> + /// The <see cref="T:System.Windows.Controls.FloatableWindow" /> to + /// associate with this + /// <see cref="T:System.Windows.Automation.Peers.FloatableWindowAutomationPeer" />. + /// </param> + public FloatableWindowAutomationPeer(FloatableWindow owner) + : base(owner) + { + if (owner == null) + { + throw new ArgumentNullException("owner"); + } + this.RefreshIsTopMostProperty(); + } + + #region AutomationPeer overrides + + /// <summary> + /// Gets the control pattern for this + /// <see cref="T:System.Windows.Automation.Peers.FloatableWindowAutomationPeer" />. + /// </summary> + /// <param name="patternInterface"> + /// One of the enumeration values. + /// </param> + /// <returns> + /// The object that implements the pattern interface, or null if the + /// specified pattern interface is not implemented by this peer. + /// </returns> + public override object GetPattern(PatternInterface patternInterface) + { + if (patternInterface == PatternInterface.Transform || patternInterface == PatternInterface.Window) + { + return this; + } + + return base.GetPattern(patternInterface); + } + + /// <summary> + /// Gets the + /// <see cref="T:System.Windows.Automation.Peers.AutomationControlType" /> + /// for the element associated with this + /// <see cref="T:System.Windows.Automation.Peers.FloatableWindowAutomationPeer" />. + /// Called by + /// <see cref="M:System.Windows.Automation.Peers.AutomationPeer.GetAutomationControlType" />. + /// </summary> + /// <returns>A value of the enumeration.</returns> + protected override AutomationControlType GetAutomationControlTypeCore() + { + return AutomationControlType.Window; + } + + /// <summary> + /// Gets the name of the class for the object associated with this + /// <see cref="T:System.Windows.Automation.Peers.FloatableWindowAutomationPeer" />. + /// Called by + /// <see cref="M:System.Windows.Automation.Peers.AutomationPeer.GetClassName" />. + /// </summary> + /// <returns> + /// A string value that represents the type of the child window. + /// </returns> + protected override string GetClassNameCore() + { + return this.Owner.GetType().Name; + } + + /// <summary> + /// Gets the text label of the + /// <see cref="T:System.Windows.Controls.FloatableWindow" /> that is + /// associated with this + /// <see cref="T:System.Windows.Automation.Peers.FloatableWindowAutomationPeer" />. + /// Called by + /// <see cref="M:System.Windows.Automation.Peers.AutomationPeer.GetName" />. + /// </summary> + /// <returns> + /// The text label of the element that is associated with this + /// automation peer. + /// </returns> + protected override string GetNameCore() + { + string name = base.GetNameCore(); + if (string.IsNullOrEmpty(name)) + { + AutomationPeer labeledBy = GetLabeledByCore(); + if (labeledBy != null) + { + name = labeledBy.GetName(); + } + + if (string.IsNullOrEmpty(name) && this.OwningFloatableWindow.Title != null) + { + name = this.OwningFloatableWindow.Title.ToString(); + } + } + return name; + } + + #endregion AutomationPeer overrides + + #region IWindowProvider + + /// <summary> + /// Gets the interaction state of the window. + /// </summary> + /// <value> + /// The interaction state of the control, as a value of the enumeration. + /// </value> + WindowInteractionState IWindowProvider.InteractionState + { + get + { + return this.OwningFloatableWindow.InteractionState; + } + } + + /// <summary> + /// Gets a value indicating whether the window is modal. + /// </summary> + /// <value> + /// True in all cases. + /// </value> + bool IWindowProvider.IsModal + { + get { return true; } + } + + /// <summary> + /// Gets a value indicating whether the window is the topmost + /// element in the z-order of layout. + /// </summary> + /// <value> + /// True if the window is topmost; otherwise, false. + /// </value> + bool IWindowProvider.IsTopmost + { + get + { + return this.IsTopMostPrivate; + } + } + + /// <summary> + /// Gets a value indicating whether the window can be maximized. + /// </summary> + /// <value>False in all cases.</value> + bool IWindowProvider.Maximizable + { + get { return false; } + } + + /// <summary> + /// Gets a value indicating whether the window can be minimized. + /// </summary> + /// <value>False in all cases.</value> + bool IWindowProvider.Minimizable + { + get { return false; } + } + + /// <summary> + /// Gets the visual state of the window. + /// </summary> + /// <value> + /// <see cref="F:System.Windows.Automation.WindowVisualState.Normal" /> + /// in all cases. + /// </value> + WindowVisualState IWindowProvider.VisualState + { + get + { + return WindowVisualState.Normal; + } + } + + /// <summary> + /// Closes the window. + /// </summary> + void IWindowProvider.Close() + { + this.OwningFloatableWindow.Close(); + } + + /// <summary> + /// Changes the visual state of the window (such as minimizing or + /// maximizing it). + /// </summary> + /// <param name="state"> + /// The visual state of the window to change to, as a value of the + /// enumeration. + /// </param> + void IWindowProvider.SetVisualState(WindowVisualState state) + { + } + + /// <summary> + /// Blocks the calling code for the specified time or until the + /// associated process enters an idle state, whichever completes first. + /// </summary> + /// <param name="milliseconds"> + /// The amount of time, in milliseconds, to wait for the associated + /// process to become idle. + /// </param> + /// <returns> + /// True if the window has entered the idle state; false if the timeout + /// occurred. + /// </returns> + bool IWindowProvider.WaitForInputIdle(int milliseconds) + { + return false; + } + + #endregion IWindowProvider + + #region ITransformProvider + + /// <summary> + /// Moves the control. + /// </summary> + /// <param name="x"> + /// The absolute screen coordinates of the left side of the control. + /// </param> + /// <param name="y"> + /// The absolute screen coordinates of the top of the control. + /// </param> + void ITransformProvider.Move(double x, double y) + { + if (x < 0) + { + x = 0; + } + + if (y < 0) + { + y = 0; + } + + if (x > this.OwningFloatableWindow.Width) + { + x = this.OwningFloatableWindow.Width; + } + + if (y > this.OwningFloatableWindow.Height) + { + y = this.OwningFloatableWindow.Height; + } + + FrameworkElement contentRoot = this.OwningFloatableWindow.ContentRoot; + + if (contentRoot != null) + { + GeneralTransform gt = contentRoot.TransformToVisual(null); + + if (gt != null) + { + Point p = gt.Transform(new Point(0, 0)); + + TransformGroup transformGroup = contentRoot.RenderTransform as TransformGroup; + + if (transformGroup == null) + { + transformGroup = new TransformGroup(); + transformGroup.Children.Add(contentRoot.RenderTransform); + } + + TranslateTransform t = new TranslateTransform(); + t.X = x - p.X; + t.Y = y - p.Y; + + if (transformGroup != null) + { + transformGroup.Children.Add(t); + contentRoot.RenderTransform = transformGroup; + } + } + } + } + + /// <summary> + /// Resizes the control. + /// </summary> + /// <param name="width">The new width of the window, in pixels.</param> + /// <param name="height"> + /// The new height of the window, in pixels. + /// </param> + void ITransformProvider.Resize(double width, double height) + { + } + + /// <summary> + /// Rotates the control. + /// </summary> + /// <param name="degrees"> + /// The number of degrees to rotate the control. A positive number + /// rotates the control clockwise. A negative number rotates the + /// control counterclockwise. + /// </param> + void ITransformProvider.Rotate(double degrees) + { + } + + /// <summary> + /// Gets a value indicating whether the element can be moved. + /// </summary> + /// <value>True in all cases.</value> + bool ITransformProvider.CanMove + { + get { return true; } + } + + /// <summary> + /// Gets a value indicating whether the element can be resized. + /// </summary> + /// <value>False in all cases.</value> + bool ITransformProvider.CanResize + { + get { return false; } + } + + /// <summary> + /// Gets a value indicating whether the element can be rotated. + /// </summary> + /// <value>False in all cases.</value> + bool ITransformProvider.CanRotate + { + get { return false; } + } + + #endregion ITransformProvider + + #region Methods + + /// <summary> + /// Returns if the FloatableWindow is the top most element. + /// </summary> + /// <returns>Bool value.</returns> + private bool GetIsTopMostCore() + { + return !(this.OwningFloatableWindow.InteractionState == WindowInteractionState.BlockedByModalWindow); + } + + /// <summary> + /// Raises PropertyChangedEvent for WindowInteractionStateProperty. + /// </summary> + /// <param name="oldValue">Old WindowInteractionStateProperty.</param> + /// <param name="newValue">New WindowInteractionStateProperty.</param> + internal void RaiseInteractionStatePropertyChangedEvent(WindowInteractionState oldValue, WindowInteractionState newValue) + { + this.RaisePropertyChangedEvent(WindowPatternIdentifiers.WindowInteractionStateProperty, oldValue, newValue); + this.RefreshIsTopMostProperty(); + } + + /// <summary> + /// Updates the IsTopMostPrivate property. + /// </summary> + private void RefreshIsTopMostProperty() + { + this.IsTopMostPrivate = this.GetIsTopMostCore(); + } + + #endregion Methods + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/FloatableWindow/GlobalSuppressions.cs Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,3 @@ +// This source is subject to the Microsoft Public License (Ms-PL). +// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. +using System.Diagnostics.CodeAnalysis; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/FloatableWindow/Properties/AssemblyInfo.cs Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,24 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Resources; +using System; +using System.Windows.Markup; + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("e26dd271-436d-483d-91e2-de61b3ffe0af")] +[assembly: AssemblyTitle("System.Windows.Controls")] +[assembly: AssemblyDescription("FloatableWindow Silverlight Control")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Tim Heuer")] +[assembly: AssemblyProduct("FloatableWindow")] +[assembly: AssemblyCopyright("Licensed under Ms-PL")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: NeutralResourcesLanguage("en-US")] +[assembly: ComVisible(false)] +[assembly: AssemblyVersion("2.0.5.0")] +[assembly: AssemblyFileVersion("3.0.40624.4")] +[assembly: CLSCompliant(true)] +[assembly: XmlnsPrefix("clr-namespace:System.Windows.Controls;assembly=FloatableWindow", "windows")] +[assembly: XmlnsDefinitionAttribute("clr-namespace:System.Windows.Controls;assembly=FloatableWindow", "System.Windows.Controls")] \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/FloatableWindow/Properties/Resources.Designer.cs Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,396 @@ +//------------------------------------------------------------------------------ +// <auto-generated> +// This code was generated by a tool. +// Runtime Version:2.0.50727.4918 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// </auto-generated> +//------------------------------------------------------------------------------ + +namespace System.Windows.Controls.Properties { + using System; + + + /// <summary> + /// A strongly-typed resource class, for looking up localized strings, etc. + /// </summary> + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// <summary> + /// Returns the cached ResourceManager instance used by this class. + /// </summary> + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("System.Windows.Controls.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// <summary> + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// </summary> + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// <summary> + /// Looks up a localized string similar to Cannot perform operation.. + /// </summary> + internal static string Automation_OperationCannotBePerformed { + get { + return ResourceManager.GetString("Automation_OperationCannotBePerformed", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to The SelectedDates collection can be changed only in a multiple selection mode. Use the SelectedDate in a single selection mode.. + /// </summary> + internal static string Calendar_CheckSelectionMode_InvalidOperation { + get { + return ResourceManager.GetString("Calendar_CheckSelectionMode_InvalidOperation", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to next button. + /// </summary> + internal static string Calendar_NextButtonName { + get { + return ResourceManager.GetString("Calendar_NextButtonName", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to DisplayMode value is not valid.. + /// </summary> + internal static string Calendar_OnDisplayModePropertyChanged_InvalidValue { + get { + return ResourceManager.GetString("Calendar_OnDisplayModePropertyChanged_InvalidValue", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to FirstDayOfWeek value is not valid.. + /// </summary> + internal static string Calendar_OnFirstDayOfWeekChanged_InvalidValue { + get { + return ResourceManager.GetString("Calendar_OnFirstDayOfWeekChanged_InvalidValue", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to The SelectedDate property cannot be set when the selection mode is None.. + /// </summary> + internal static string Calendar_OnSelectedDateChanged_InvalidOperation { + get { + return ResourceManager.GetString("Calendar_OnSelectedDateChanged_InvalidOperation", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to SelectedDate value is not valid.. + /// </summary> + internal static string Calendar_OnSelectedDateChanged_InvalidValue { + get { + return ResourceManager.GetString("Calendar_OnSelectedDateChanged_InvalidValue", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to SelectionMode value is not valid.. + /// </summary> + internal static string Calendar_OnSelectionModeChanged_InvalidValue { + get { + return ResourceManager.GetString("Calendar_OnSelectionModeChanged_InvalidValue", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to previous button. + /// </summary> + internal static string Calendar_PreviousButtonName { + get { + return ResourceManager.GetString("Calendar_PreviousButtonName", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to Value is not valid.. + /// </summary> + internal static string Calendar_UnSelectableDates { + get { + return ResourceManager.GetString("Calendar_UnSelectableDates", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to Blackout Day - {0}. + /// </summary> + internal static string CalendarAutomationPeer_BlackoutDayHelpText { + get { + return ResourceManager.GetString("CalendarAutomationPeer_BlackoutDayHelpText", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to calendar button. + /// </summary> + internal static string CalendarAutomationPeer_CalendarButtonLocalizedControlType { + get { + return ResourceManager.GetString("CalendarAutomationPeer_CalendarButtonLocalizedControlType", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to day button. + /// </summary> + internal static string CalendarAutomationPeer_DayButtonLocalizedControlType { + get { + return ResourceManager.GetString("CalendarAutomationPeer_DayButtonLocalizedControlType", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to Decade. + /// </summary> + internal static string CalendarAutomationPeer_DecadeMode { + get { + return ResourceManager.GetString("CalendarAutomationPeer_DecadeMode", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to Month. + /// </summary> + internal static string CalendarAutomationPeer_MonthMode { + get { + return ResourceManager.GetString("CalendarAutomationPeer_MonthMode", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to Year. + /// </summary> + internal static string CalendarAutomationPeer_YearMode { + get { + return ResourceManager.GetString("CalendarAutomationPeer_YearMode", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to This type of Collection does not support changes to its SourceCollection from a thread different from the Dispatcher thread.. + /// </summary> + internal static string CalendarCollection_MultiThreadedCollectionChangeNotSupported { + get { + return ResourceManager.GetString("CalendarCollection_MultiThreadedCollectionChangeNotSupported", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to Cannot call Show() on a ChildWindow that is in the visual tree. ChildWindow should be the top-most element in the .xaml file.. + /// </summary> + internal static string ChildWindow_InvalidOperation { + get { + return ResourceManager.GetString("ChildWindow_InvalidOperation", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to Show Calendar. + /// </summary> + internal static string DatePicker_DropDownButtonName { + get { + return ResourceManager.GetString("DatePicker_DropDownButtonName", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to DatePickerFormat value is not valid.. + /// </summary> + internal static string DatePicker_OnSelectedDateFormatChanged_InvalidValue { + get { + return ResourceManager.GetString("DatePicker_OnSelectedDateFormatChanged_InvalidValue", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to <{0}>. + /// </summary> + internal static string DatePicker_WatermarkText { + get { + return ResourceManager.GetString("DatePicker_WatermarkText", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to date picker. + /// </summary> + internal static string DatePickerAutomationPeer_LocalizedControlType { + get { + return ResourceManager.GetString("DatePickerAutomationPeer_LocalizedControlType", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to Cannot Throw Null Exception. + /// </summary> + internal static string DatePickerDateValidationErrorEventArgs_ThrowException_NoException { + get { + return ResourceManager.GetString("DatePickerDateValidationErrorEventArgs_ThrowException_NoException", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to <enter text here>. + /// </summary> + internal static string DatePickerTextBox_DefaultWatermarkText { + get { + return ResourceManager.GetString("DatePickerTextBox_DefaultWatermarkText", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to The template part {0} is not an instance of {1}.. + /// </summary> + internal static string DatePickerTextBox_TemplatePartIsOfIncorrectType { + get { + return ResourceManager.GetString("DatePickerTextBox_TemplatePartIsOfIncorrectType", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to DateTime value is in the wrong format.. + /// </summary> + internal static string DateTimeTypeConverter_FormatException { + get { + return ResourceManager.GetString("DateTimeTypeConverter_FormatException", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to ConstructorParameters cannot be changed because ObjectDataProvider is using a user-assigned ObjectInstance.. + /// </summary> + internal static string ParameterCollection_EnsureCanChangeCollection_IsReadOnly { + get { + return ResourceManager.GetString("ParameterCollection_EnsureCanChangeCollection_IsReadOnly", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to The elementName should not be empty.. + /// </summary> + internal static string ResolveElementNameEventArgs_ctor_ElementNameEmpty { + get { + return ResourceManager.GetString("ResolveElementNameEventArgs_ctor_ElementNameEmpty", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to The RoutedPropertyChangingEvent cannot be canceled!. + /// </summary> + internal static string RoutedPropertyChangingEventArgs_CancelSet_InvalidOperation { + get { + return ResourceManager.GetString("RoutedPropertyChangingEventArgs_CancelSet_InvalidOperation", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to Unable to cast object of type '{0}' to type 'System.Windows.Controls.TabItem'.. + /// </summary> + internal static string TabControl_InvalidChild { + get { + return ResourceManager.GetString("TabControl_InvalidChild", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to '{0}' is not a valid value for property 'SelectedIndex'. + /// </summary> + internal static string TabControl_InvalidIndex { + get { + return ResourceManager.GetString("TabControl_InvalidIndex", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to Cannot set read-only property SelectedItem.. + /// </summary> + internal static string TreeView_OnSelectedItemPropertyChanged_InvalidWrite { + get { + return ResourceManager.GetString("TreeView_OnSelectedItemPropertyChanged_InvalidWrite", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to Cannot set read-only property SelectedValue.. + /// </summary> + internal static string TreeView_OnSelectedValuePropertyChanged_InvalidWrite { + get { + return ResourceManager.GetString("TreeView_OnSelectedValuePropertyChanged_InvalidWrite", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to Cannot set read-only property HasItems.. + /// </summary> + internal static string TreeViewItem_OnHasItemsPropertyChanged_InvalidWrite { + get { + return ResourceManager.GetString("TreeViewItem_OnHasItemsPropertyChanged_InvalidWrite", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to Cannot set read-only property IsSelectionActive.. + /// </summary> + internal static string TreeViewItem_OnIsSelectionActivePropertyChanged_InvalidWrite { + get { + return ResourceManager.GetString("TreeViewItem_OnIsSelectionActivePropertyChanged_InvalidWrite", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to '{0}' is unable to convert '{1}' to '{2}'.. + /// </summary> + internal static string TypeConverters_Convert_CannotConvert { + get { + return ResourceManager.GetString("TypeConverters_Convert_CannotConvert", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to '{0}' cannot convert from '{1}'.. + /// </summary> + internal static string TypeConverters_ConvertFrom_CannotConvertFromType { + get { + return ResourceManager.GetString("TypeConverters_ConvertFrom_CannotConvertFromType", resourceCulture); + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/FloatableWindow/Properties/Resources.resx Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,128 @@ +<?xml version="1.0" encoding="utf-8"?> +<root> + <!-- + Microsoft ResX Schema + + Version 2.0 + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes + associated with the data types. + + Example: + + ... ado.net/XML headers & schema ... + <resheader name="resmimetype">text/microsoft-resx</resheader> + <resheader name="version">2.0</resheader> + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> + <value>[base64 mime encoded serialized .NET Framework object]</value> + </data> + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> + <comment>This is a comment</comment> + </data> + + There are any number of "resheader" rows that contain simple + name/value pairs. + + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the + mimetype set. + + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not + extensible. For a given mimetype the value must be set accordingly: + + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can + read any of the formats listed below. + + mimetype: application/x-microsoft.net.object.binary.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.soap.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> + <xsd:element name="root" msdata:IsDataSet="true"> + <xsd:complexType> + <xsd:choice maxOccurs="unbounded"> + <xsd:element name="metadata"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> + </xsd:sequence> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="assembly"> + <xsd:complexType> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="data"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="resheader"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" /> + </xsd:complexType> + </xsd:element> + </xsd:choice> + </xsd:complexType> + </xsd:element> + </xsd:schema> + <resheader name="resmimetype"> + <value>text/microsoft-resx</value> + </resheader> + <resheader name="version"> + <value>2.0</value> + </resheader> + <resheader name="reader"> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name="writer"> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <data name="Automation_OperationCannotBePerformed" xml:space="preserve"> + <value>Cannot perform operation.</value> + <comment>Exception thrown by automation peers.</comment> + </data> + <data name="ChildWindow_InvalidOperation" xml:space="preserve"> + <value>Cannot call Show() on a ChildWindow that is in the visual tree. ChildWindow should be the top-most element in the .xaml file.</value> + <comment>Exception thrown when the ChildWindow is in the visual tree and Show() is called on it.</comment> + </data> +</root> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/FloatableWindow/README.txt Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,7 @@ +This is an adaptation of the ChildWindow control for Silverlight in the +Microsoft Silverlight SDK. The ChildWindow control is licensed under the +Ms-PL license, and as-such, FloatableWindow is also licensed under Ms-PL. + +This was build as a proof of concept and no warranties are provided, +implied or otherwise. The author who adapted this control is +Tim Heuer, who may be contacted at http://timheuer.com/blog/. \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/FloatableWindow/ResizeMode.cs Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,12 @@ +using System; + +namespace System.Windows +{ + public enum ResizeMode + { + NoResize = 0, + CanMinimize = 1, + CanResize = 2, + CanResizeWithGrip = 3, + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/FloatableWindow/themes/generic.xaml Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,276 @@ +<ResourceDictionary + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:controls="clr-namespace:System.Windows.Controls" + xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"> + + <Storyboard x:Name="ResizerEnter"> + <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="Resizer" Storyboard.TargetProperty="(UIElement.Opacity)"> + <EasingDoubleKeyFrame KeyTime="00:00:00" Value="1"/> + </DoubleAnimationUsingKeyFrames> + </Storyboard> + <Storyboard x:Name="ResizerLeave"> + <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="Resizer" Storyboard.TargetProperty="(UIElement.Opacity)"> + <EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"/> + </DoubleAnimationUsingKeyFrames> + </Storyboard> + <Style x:Key="ResizerStyle" TargetType="Thumb"> + <Setter Property="Background" Value="#FF1F3B53"/> + <Setter Property="BorderThickness" Value="1"/> + <Setter Property="IsTabStop" Value="False"/> + <Setter Property="BorderBrush"> + <Setter.Value> + <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> + <GradientStop Color="#FFA3AEB9" Offset="0"/> + <GradientStop Color="#FF8399A9" Offset="0.375"/> + <GradientStop Color="#FF718597" Offset="0.375"/> + <GradientStop Color="#FF617584" Offset="1"/> + </LinearGradientBrush> + </Setter.Value> + </Setter> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="Thumb"> + <Path Fill="#FFB1B1B1" Stretch="Fill" Height="20" Width="20" UseLayoutRounding="False" Data="M15.499995,0.5 L15.499995,15.5 L0.5,15.5 z"> + <VisualStateManager.VisualStateGroups> + <VisualStateGroup x:Name="CommonStates"> + <VisualState x:Name="Normal"/> + <VisualState x:Name="MouseOver"/> + <VisualState x:Name="Pressed"/> + <VisualState x:Name="Disabled"/> + </VisualStateGroup> + <VisualStateGroup x:Name="FocusStates"> + <VisualState x:Name="Unfocused"/> + <VisualState x:Name="Focused"/> + </VisualStateGroup> + </VisualStateManager.VisualStateGroups> + </Path> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + <Style TargetType="controls:FloatableWindow"> + <Setter Property="IsTabStop" Value="false"/> + <Setter Property="TabNavigation" Value="Cycle"/> + <Setter Property="HorizontalAlignment" Value="Center"/> + <Setter Property="VerticalAlignment" Value="Center"/> + <Setter Property="HorizontalContentAlignment" Value="Stretch"/> + <Setter Property="VerticalContentAlignment" Value="Stretch"/> + <Setter Property="BorderThickness" Value="1"/> + <Setter Property="BorderBrush"> + <Setter.Value> + <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> + <GradientStop Color="#FFA3AEB9" Offset="0"/> + <GradientStop Color="#FF8399A9" Offset="0.375"/> + <GradientStop Color="#FF718597" Offset="0.375"/> + <GradientStop Color="#FF617584" Offset="1"/> + </LinearGradientBrush> + </Setter.Value> + </Setter> + <Setter Property="OverlayBrush"> + <Setter.Value> + <SolidColorBrush Color="#7F000000"/> + </Setter.Value> + </Setter> + <Setter Property="OverlayOpacity" Value="1"/> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="controls:FloatableWindow"> + <Grid x:Name="Root"> + <Grid.Resources> + <Style x:Key="ButtonStyle" TargetType="Button"> + <Setter Property="Background" Value="#FF1F3B53"/> + <Setter Property="Foreground" Value="#FF000000"/> + <Setter Property="Padding" Value="3"/> + <Setter Property="BorderThickness" Value="1"/> + <Setter Property="BorderBrush"> + <Setter.Value> + <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> + <GradientStop Color="#FFA3AEB9" Offset="0"/> + <GradientStop Color="#FF8399A9" Offset="0.375"/> + <GradientStop Color="#FF718597" Offset="0.375"/> + <GradientStop Color="#FF617584" Offset="1"/> + </LinearGradientBrush> + </Setter.Value> + </Setter> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="Button"> + <Grid HorizontalAlignment="Center" VerticalAlignment="Center" Width="15" Height="14" Background="#02FFFFFF" x:Name="grid"> + <vsm:VisualStateManager.VisualStateGroups> + <vsm:VisualStateGroup x:Name="CommonStates"> + <vsm:VisualState x:Name="Normal"/> + <vsm:VisualState x:Name="MouseOver"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="X_Fuzz2" Storyboard.TargetProperty="Visibility"> + <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="X_Fuzz1" Storyboard.TargetProperty="Visibility"> + <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="X_Fuzz0" Storyboard.TargetProperty="Visibility"> + <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" /> + </ObjectAnimationUsingKeyFrames> + <DoubleAnimation Duration="0" Storyboard.TargetName="X" Storyboard.TargetProperty="Opacity" To="0.95"/> + </Storyboard> + </vsm:VisualState> + <vsm:VisualState x:Name="Pressed"> + <Storyboard> + <DoubleAnimation Duration="0" Storyboard.TargetName="X" Storyboard.TargetProperty="Opacity" To="0.85"/> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="X_Fuzz2" Storyboard.TargetProperty="Visibility"> + <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="X_Fuzz1" Storyboard.TargetProperty="Visibility"> + <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="X_Fuzz0" Storyboard.TargetProperty="Visibility"> + <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" /> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </vsm:VisualState> + <vsm:VisualState x:Name="Disabled"> + <Storyboard> + <DoubleAnimation Duration="0" Storyboard.TargetName="X" Storyboard.TargetProperty="Opacity" To="0.5"/> + </Storyboard> + </vsm:VisualState> + </vsm:VisualStateGroup> + </vsm:VisualStateManager.VisualStateGroups> + <Path HorizontalAlignment="Center" Margin="0,-1,0,0" Width="9" Fill="#14C51900" Stretch="Fill" Data="F1 M 6.742676,3.852539 L 9.110840,1.559570 L 8.910645,0.500000 L 6.838379,0.500000 L 4.902832,2.435547 L 2.967285,0.500000 L 0.895020,0.500000 L 0.694824,1.559570 L 3.062988,3.852539 L 0.527832,6.351563 L 0.689941,7.600586 L 2.967285,7.600586 L 4.897949,5.575195 L 6.854004,7.600586 L 9.115723,7.600586 L 9.277832,6.351563 L 6.742676,3.852539 Z" x:Name="X_Fuzz2" Stroke="#14C51900" Height="8" VerticalAlignment="Center" Opacity="1" RenderTransformOrigin="0.5,0.5" Visibility="Collapsed"> + <Path.RenderTransform> + <TransformGroup> + <ScaleTransform ScaleX="1.3" ScaleY="1.3"/> + </TransformGroup> + </Path.RenderTransform> + </Path> + <Path HorizontalAlignment="Center" Margin="0,-1,0,0" Width="9" Fill="#1EC51900" Stretch="Fill" Data="F1 M 6.742676,3.852539 L 9.110840,1.559570 L 8.910645,0.500000 L 6.838379,0.500000 L 4.902832,2.435547 L 2.967285,0.500000 L 0.895020,0.500000 L 0.694824,1.559570 L 3.062988,3.852539 L 0.527832,6.351563 L 0.689941,7.600586 L 2.967285,7.600586 L 4.897949,5.575195 L 6.854004,7.600586 L 9.115723,7.600586 L 9.277832,6.351563 L 6.742676,3.852539 Z" x:Name="X_Fuzz1" Stroke="#1EC51900" Height="8" VerticalAlignment="Center" Opacity="1" RenderTransformOrigin="0.5,0.5" Visibility="Collapsed"> + <Path.RenderTransform> + <TransformGroup> + <ScaleTransform ScaleX="1.1" ScaleY="1.1"/> + </TransformGroup> + </Path.RenderTransform> + </Path> + <Path HorizontalAlignment="Center" Margin="0,-1,0,0" Width="9" Fill="#FFC51900" Stretch="Fill" Data="F1 M 6.742676,3.852539 L 9.110840,1.559570 L 8.910645,0.500000 L 6.838379,0.500000 L 4.902832,2.435547 L 2.967285,0.500000 L 0.895020,0.500000 L 0.694824,1.559570 L 3.062988,3.852539 L 0.527832,6.351563 L 0.689941,7.600586 L 2.967285,7.600586 L 4.897949,5.575195 L 6.854004,7.600586 L 9.115723,7.600586 L 9.277832,6.351563 L 6.742676,3.852539 Z" x:Name="X_Fuzz0" Stroke="#FFC51900" Height="8" VerticalAlignment="Center" Opacity="1" Visibility="Collapsed"/> + <Path HorizontalAlignment="Center" Margin="0,-1,0,0" Width="9" Fill="#FFFFFFFF" Stretch="Fill" Data="F1 M 6.742676,3.852539 L 9.110840,1.559570 L 8.910645,0.500000 L 6.838379,0.500000 L 4.902832,2.435547 L 2.967285,0.500000 L 0.895020,0.500000 L 0.694824,1.559570 L 3.062988,3.852539 L 0.527832,6.351563 L 0.689941,7.600586 L 2.967285,7.600586 L 4.897949,5.575195 L 6.854004,7.600586 L 9.115723,7.600586 L 9.277832,6.351563 L 6.742676,3.852539 Z" x:Name="X" Height="8" VerticalAlignment="Center" Opacity="0.7"> + <Path.Stroke> + <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> + <GradientStop Color="#FF313131" Offset="1"/> + <GradientStop Color="#FF8E9092" Offset="0"/> + </LinearGradientBrush> + </Path.Stroke> + </Path> + </Grid> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + </Grid.Resources> + <vsm:VisualStateManager.VisualStateGroups> + <vsm:VisualStateGroup x:Name="WindowStates"> + <vsm:VisualState x:Name="Open"> + <Storyboard> + <DoubleAnimationUsingKeyFrames BeginTime="0" Storyboard.TargetName="Overlay" Storyboard.TargetProperty="Opacity"> + <EasingDoubleKeyFrame KeyTime="0" Value="0"/> + <EasingDoubleKeyFrame KeyTime="00:00:00.3" Value="1"/> + </DoubleAnimationUsingKeyFrames> + <DoubleAnimationUsingKeyFrames BeginTime="0" Storyboard.TargetName="ContentRoot" Storyboard.TargetProperty="(RenderTransform).(Children)[0].ScaleX"> + <SplineDoubleKeyFrame KeyTime="0" Value="0"/> + <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="0"/> + <SplineDoubleKeyFrame KeyTime="00:00:00.4" Value="1"/> + <SplineDoubleKeyFrame KeySpline="0,0,0.5,1" KeyTime="00:00:00.45" Value="1.05"/> + <SplineDoubleKeyFrame KeyTime="00:00:00.55" Value="1"/> + </DoubleAnimationUsingKeyFrames> + <DoubleAnimationUsingKeyFrames BeginTime="0" Storyboard.TargetName="ContentRoot" Storyboard.TargetProperty="(RenderTransform).(Children)[0].ScaleY"> + <SplineDoubleKeyFrame KeyTime="0" Value="0"/> + <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="0"/> + <SplineDoubleKeyFrame KeyTime="00:00:00.4" Value="1"/> + <SplineDoubleKeyFrame KeySpline="0,0,0.5,1" KeyTime="00:00:00.45" Value="1.05"/> + <SplineDoubleKeyFrame KeyTime="00:00:00.55" Value="1"/> + </DoubleAnimationUsingKeyFrames> + </Storyboard> + </vsm:VisualState> + <vsm:VisualState x:Name="Closed"> + <Storyboard> + <DoubleAnimationUsingKeyFrames BeginTime="0" Storyboard.TargetName="Overlay" Storyboard.TargetProperty="Opacity"> + <EasingDoubleKeyFrame KeyTime="0" Value="1"/> + <EasingDoubleKeyFrame KeyTime="00:00:00.3" Value="0"/> + </DoubleAnimationUsingKeyFrames> + <DoubleAnimationUsingKeyFrames BeginTime="0" Storyboard.TargetName="ContentRoot" Storyboard.TargetProperty="(RenderTransform).(Children)[0].ScaleX"> + <SplineDoubleKeyFrame KeyTime="00:00:00.2" Value="1"/> + <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="1.05"/> + <SplineDoubleKeyFrame KeyTime="00:00:00.45" Value="0"/> + </DoubleAnimationUsingKeyFrames> + <DoubleAnimationUsingKeyFrames BeginTime="0" Storyboard.TargetName="ContentRoot" Storyboard.TargetProperty="(RenderTransform).(Children)[0].ScaleY"> + <SplineDoubleKeyFrame KeyTime="00:00:00.2" Value="1"/> + <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="1.05"/> + <SplineDoubleKeyFrame KeyTime="00:00:00.45" Value="0"/> + </DoubleAnimationUsingKeyFrames> + </Storyboard> + </vsm:VisualState> + </vsm:VisualStateGroup> + </vsm:VisualStateManager.VisualStateGroups> + <Grid x:Name="Overlay" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="0" Background="{TemplateBinding OverlayBrush}" Opacity="{TemplateBinding OverlayOpacity}"/> + <Grid x:Name="ContentRoot" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}" RenderTransformOrigin="0.5,0.5" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}"> + <Grid.RenderTransform> + <TransformGroup> + <ScaleTransform /> + <SkewTransform /> + <RotateTransform /> + <TranslateTransform /> + </TransformGroup> + </Grid.RenderTransform> + <Border BorderThickness="1" CornerRadius="2" BorderBrush="#14000000" Background="#14000000" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="-1"/> + <Border BorderThickness="1" CornerRadius="2.25" BorderBrush="#0F000000" Background="#0F000000" HorizontalAlignment="Stretch" Margin="-2" VerticalAlignment="Stretch"/> + <Border BorderThickness="1" CornerRadius="2.5" BorderBrush="#0C000000" Background="#0C000000" HorizontalAlignment="Stretch" Margin="-3" VerticalAlignment="Stretch"/> + <Border BorderThickness="1" CornerRadius="2.75" BorderBrush="#0A000000" Background="#0A000000" HorizontalAlignment="Stretch" Margin="-4" VerticalAlignment="Stretch"/> + <Border Background="#FFFFFFFF" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="2"> + <Border CornerRadius="1.5" Margin="1"> + <Border.Background> + <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> + <GradientStop Color="#FFE5E8EB" Offset="1"/> + <GradientStop Color="#FFF6F8F9" Offset="0"/> + </LinearGradientBrush> + </Border.Background> + <Grid> + <Grid.RowDefinitions> + <RowDefinition Height="Auto"/> + <RowDefinition/> + </Grid.RowDefinitions> + <Border x:Name="Chrome" Width="Auto" BorderBrush="#FFFFFFFF" BorderThickness="0,0,0,1"> + <Border.Background> + <LinearGradientBrush EndPoint="0.5,0.528" StartPoint="0.5,0"> + <GradientStop Color="#FFE5E8EB" Offset="1"/> + <GradientStop Color="#FFFEFEFE" Offset="0"/> + </LinearGradientBrush> + </Border.Background> + <Grid Height="Auto" Width="Auto"> + <Grid.ColumnDefinitions> + <ColumnDefinition/> + <ColumnDefinition Width="30"/> + </Grid.ColumnDefinitions> + <ContentControl Content="{TemplateBinding Title}" + IsTabStop="False" + FontWeight="Bold" + HorizontalAlignment="Stretch" + VerticalAlignment="Center" + Margin="6,0,6,0"/> + <Button x:Name="CloseButton" Grid.Column="1" IsTabStop="False" HorizontalAlignment="Center" VerticalAlignment="Center" Width="15" Height="14" Style="{StaticResource ButtonStyle}"/> + </Grid> + </Border> + <Border Background="{TemplateBinding Background}" Margin="7" Grid.Row="1"> + <ContentPresenter x:Name="ContentPresenter" Content="{TemplateBinding Content}" + ContentTemplate="{TemplateBinding ContentTemplate}" + HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" + VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> + </Border> + <Path x:Name="Resizer" Opacity=".25" Fill="#FFB1B1B1" Stretch="Fill" Height="20" Width="20" UseLayoutRounding="False" Grid.Row="1" Data="M15.499995,0.5 L15.499995,15.5 L0.5,15.5 z" HorizontalAlignment="Right" VerticalAlignment="Bottom"/> + </Grid> + </Border> + </Border> + </Grid> + </Grid> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + +</ResourceDictionary> \ No newline at end of file
--- a/SilverlightGlimpse/Models/BrokenBinding.cs Sat Apr 21 21:20:05 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -using System; - -namespace SilverlightGlimpse.Models -{ - public class BrokenBinding - { - #region Fields - - private string _controlName = string.Empty; - private string _controlTypeName = string.Empty; - private string _path = string.Empty; - private string _propertyName = string.Empty; - - #endregion - - #region Constructor - - public BrokenBinding(string controlName, string controlTypeName, string propertyName, string path) - { - _controlName = controlName; - _controlTypeName = controlTypeName; - _propertyName = propertyName; - _path = path; - } - - #endregion - - #region Properties - - public string ControlName { get { return string.IsNullOrEmpty(_controlName) ? "(none)" : _controlName; } } - public string ControlTypeName { get { return _controlTypeName; } } - public string Path { get { return _path; } } - public string PropertyName { get { return _propertyName; } } - - #endregion - - #region Methods - - public override string ToString() - { - return string.Format( - "Control Name: {0}, Type: {1}, Property: {2}, Path: {3}", - this.ControlName, - this.ControlTypeName, - this.PropertyName, - this.Path); - } - - #endregion - } -} \ No newline at end of file
--- a/SilverlightGlimpse/Models/ExceptionWrapper.cs Sat Apr 21 21:20:05 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -using System; -using System.Windows.Controls; - -namespace SilverlightGlimpse.Models -{ - public class ExceptionWrapper - { - #region Fields - - private bool _isValidationException = false; - private ValidationErrorEventAction _enumAction = ValidationErrorEventAction.Added; - private Exception _exception; - private string _controlName = string.Empty; - - #endregion - - #region Constructor - - public ExceptionWrapper(Exception e) - { - _exception = e; - } - - #endregion - - #region Properties - - public ExceptionWrapper(ValidationErrorEventAction enumAction, string controlName, Exception validationException) - { - _enumAction = enumAction; - _controlName = controlName; - _exception = validationException; - _isValidationException = true; - } - - public ValidationErrorEventAction Action { get { return _enumAction; } } - public string ControlName { get { return _controlName; } } - public Exception Exception { get { return _exception; } } - public bool IsValidationException { get { return _isValidationException; } } - - #endregion - - #region Methods - - public override string ToString() - { - return _isValidationException - ? string.Format("({0}) - {1}", this.Action, Exception.Message) - : Exception.Message; - } - - #endregion - } -} \ No newline at end of file
--- a/SilverlightGlimpse/Properties/AppManifest.xml Sat Apr 21 21:20:05 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" -> - <Deployment.Parts> - </Deployment.Parts> -</Deployment>
--- a/SilverlightGlimpse/Properties/AssemblyInfo.cs Sat Apr 21 21:20:05 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("SilverlightGlimpse")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("SilverlightGlimpse")] -[assembly: AssemblyCopyright("Copyright © 2012")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("52ef33ca-e923-41ef-a7c8-98ec475bc956")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")]
--- a/SilverlightGlimpse/Services/GlimpseService.cs Sat Apr 21 21:20:05 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,123 +0,0 @@ -using System; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.Windows; -using System.Windows.Controls; -using SilverlightGlimpse.Controls; -using SilverlightGlimpse.Models; - -namespace SilverlightGlimpse.Services -{ - public class GlimpseService - { - #region Fields - - private static GlimpseService _instance; - - #endregion - - #region Private constructor - - private GlimpseService() - { - } - - #endregion - - #region Properties - - public static GlimpseService CreateInstance - { - get { return (_instance == null) ? _instance = new GlimpseService() : _instance; } - } - - internal Application App { get; private set; } - internal FloatableWindow GlimpseWindow { get; set;} - internal string HostApplicationName { get; set; } - internal ObservableCollection<ExceptionWrapper> HostExceptions { get; private set; } - internal FrameworkElement RootVisual { get; private set; } - - #endregion - - #region Creation and Loading - - public void DisplayLoadFailure(Application app, Exception ex, string hostApplicationName) - { - Debug.WriteLine("{0} had exception. {1}", this.HostApplicationName, ex.ToString()); - App = app; - RootVisual = new LoadExceptionViewer(ex, hostApplicationName); - - RootVisual.BindingValidationError += HostRootVisual_BindingValidationError; - App.UnhandledException += Application_UnhandledException; - } - - public void Load(Application app, string hostApplicationName) - { - this.App = app; - this.RootVisual = App.RootVisual as FrameworkElement; - this.HostApplicationName = hostApplicationName; - - RootVisual.BindingValidationError += HostRootVisual_BindingValidationError; - App.UnhandledException += Application_UnhandledException; - - FloatableWindow window = new FloatableWindow(); - window.Title = this.HostApplicationName; - window.Content = new GlimpseViewer(); - - if (Double.IsNaN(this.RootVisual.Width)) - { - //if the host control is autosized (consumes the browser window) then locate Glimpse in the top, left - window.Show(); - } - else - { - //if the host is fixed size then attempt to locate the popup control in the upper right corner - var dblLeft = this.RootVisual.Width - 200; - - if (dblLeft < 0) - dblLeft = 0; - - window.Show(); - } - } - #endregion - - #region Events handlers - - private void HostRootVisual_BindingValidationError(object sender, ValidationErrorEventArgs e) - { - string controlName = "(none)"; - Control control = e.OriginalSource as Control; - - if (control != null && !string.IsNullOrEmpty(control.Name)) - { - controlName = control.Name; - } - - Exception ex = e.Error.Exception; - - while (ex != null) - { - this.HostExceptions.Add(new ExceptionWrapper(e.Action, controlName, e.Error.Exception)); - ex = ex.InnerException; - } - } - - private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) - { - Debug.WriteLine("{0} had exception. {1}", this.HostApplicationName, e.ExceptionObject.ToString()); - - Exception ex = e.ExceptionObject; - - while (ex != null) - { - this.HostExceptions.Add(new ExceptionWrapper(ex)); - ex = ex.InnerException; - } - - e.Handled = true; - } - - #endregion - } -} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse.Test/App.xaml Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,8 @@ +<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + x:Class="SilverlightGlimpse.Test.App" + > + <Application.Resources> + + </Application.Resources> +</Application>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse.Test/App.xaml.cs Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using SilverlightGlimpse.Services; +//using Glimpse; + +namespace SilverlightGlimpse.Test +{ + public partial class App : Application + { + + public App() + { + this.Startup += this.Application_Startup; + this.Exit += this.Application_Exit; + this.UnhandledException += this.Application_UnhandledException; + + InitializeComponent(); + } + + private void Application_Startup(object sender, StartupEventArgs e) + { + string appName = "SilverlightGlimpse"; + + try + { + this.RootVisual = new MainPage(); + GlimpseService.CreateInstance.Load(this, appName); + } + catch (Exception ex) + { + GlimpseService.CreateInstance.DisplayLoadFailure(this, ex); + } + } + + private void Application_Exit(object sender, EventArgs e) + { + + } + + private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) + { + // If the app is running outside of the debugger then report the exception using + // the browser's exception mechanism. On IE this will display it a yellow alert + // icon in the status bar and Firefox will display a script error. + if (!System.Diagnostics.Debugger.IsAttached) + { + + // NOTE: This will allow the application to continue running after an exception has been thrown + // but not handled. + // For production applications this error handling should be replaced with something that will + // report the error to the website and stop the application. + e.Handled = true; + Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); }); + } + } + + private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e) + { + try + { + string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace; + errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n"); + + System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");"); + } + catch (Exception) + { + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse.Test/MainPage.xaml Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,30 @@ +<UserControl x:Class="SilverlightGlimpse.Test.MainPage" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + d:DesignHeight="300" + d:DesignWidth="400" + mc:Ignorable="d"> + + <Grid x:Name="LayoutRoot" Background="White"> + <Grid.RowDefinitions> + <RowDefinition Height="100" /> + </Grid.RowDefinitions> + + <Button Width="150" + Height="60" + Click="Button_Click" + Content="Open form" /> + <ListBox x:Name="Listbox1" Grid.Row="1"> + <ListBox.ItemTemplate> + <DataTemplate> + <StackPanel> + <TextBlock Text="{Binding Id }" /> + <TextBlock Text="{Binding FAIL}" /> + </StackPanel> + </DataTemplate> + </ListBox.ItemTemplate> + </ListBox> + </Grid> +</UserControl>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse.Test/MainPage.xaml.cs Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using System.Dynamic; + +namespace SilverlightGlimpse.Test +{ + public partial class MainPage : UserControl + { + public MainPage() + { + InitializeComponent(); + throw new Exception("Test"); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + var list = new List<object>(5) + { + new { Id = 1 , Name = "Steve"}, + new { Id = 2 , Name = "Dave"}, + new { Id = 3 , Name = "Bob"}, + new { Id = 4 , Name = "Rich"}, + new { Id = 5 , Name = "Clare"} + }; + this.DataContext = list; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse.Test/Properties/AppManifest.xml Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,6 @@ +<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" +> + <Deployment.Parts> + </Deployment.Parts> +</Deployment>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse.Test/Properties/AssemblyInfo.cs Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SilverlightGlimpse.Test")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SilverlightGlimpse.Test")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("416aacbe-6a1b-495f-9d5e-8f975d2e3f58")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse.Test/SilverlightGlimpse.Test.csproj Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,117 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProductVersion>8.0.50727</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{212DBD25-6C98-45EB-9974-51D04D8B6549}</ProjectGuid> + <ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>SilverlightGlimpse.Test</RootNamespace> + <AssemblyName>SilverlightGlimpse.Test</AssemblyName> + <TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier> + <TargetFrameworkVersion>v5.0</TargetFrameworkVersion> + <SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion> + <SilverlightApplication>true</SilverlightApplication> + <SupportedCultures> + </SupportedCultures> + <XapOutputs>true</XapOutputs> + <GenerateSilverlightManifest>true</GenerateSilverlightManifest> + <XapFilename>SilverlightGlimpse.Test.xap</XapFilename> + <SilverlightManifestTemplate>Properties\AppManifest.xml</SilverlightManifestTemplate> + <SilverlightAppEntry>SilverlightGlimpse.Test.App</SilverlightAppEntry> + <TestPageFileName>SilverlightGlimpse.TestTestPage.html</TestPageFileName> + <CreateTestPage>true</CreateTestPage> + <ValidateXaml>true</ValidateXaml> + <EnableOutOfBrowser>false</EnableOutOfBrowser> + <OutOfBrowserSettingsFile>Properties\OutOfBrowserSettings.xml</OutOfBrowserSettingsFile> + <UsePlatformExtensions>false</UsePlatformExtensions> + <ThrowErrorsInValidation>true</ThrowErrorsInValidation> + <LinkedServerProject> + </LinkedServerProject> + </PropertyGroup> + <!-- This property group is only here to support building this project using the + MSBuild 3.5 toolset. In order to work correctly with this older toolset, it needs + to set the TargetFrameworkVersion to v3.5 --> + <PropertyGroup Condition="'$(MSBuildToolsVersion)' == '3.5'"> + <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>Bin\Debug</OutputPath> + <DefineConstants>DEBUG;TRACE;SILVERLIGHT</DefineConstants> + <NoStdLib>true</NoStdLib> + <NoConfig>true</NoConfig> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>Bin\Release</OutputPath> + <DefineConstants>TRACE;SILVERLIGHT</DefineConstants> + <NoStdLib>true</NoStdLib> + <NoConfig>true</NoConfig> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="mscorlib" /> + <Reference Include="System.Windows" /> + <Reference Include="system" /> + <Reference Include="System.Core" /> + <Reference Include="System.Net" /> + <Reference Include="System.Windows.Controls, Version=5.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\Libs\System.Windows.Controls.dll</HintPath> + </Reference> + <Reference Include="System.Xml" /> + <Reference Include="System.Windows.Browser" /> + </ItemGroup> + <ItemGroup> + <Compile Include="App.xaml.cs"> + <DependentUpon>App.xaml</DependentUpon> + </Compile> + <Compile Include="MainPage.xaml.cs"> + <DependentUpon>MainPage.xaml</DependentUpon> + </Compile> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <ItemGroup> + <ApplicationDefinition Include="App.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </ApplicationDefinition> + <Page Include="MainPage.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> + </ItemGroup> + <ItemGroup> + <None Include="Properties\AppManifest.xml" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\SilverlightGlimpse\SilverlightGlimpse.csproj"> + <Project>{BB51026B-2864-4389-AACA-0BBDF1926E46}</Project> + <Name>SilverlightGlimpse</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> + <ProjectExtensions> + <VisualStudio> + <FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}"> + <SilverlightProjectProperties /> + </FlavorProperties> + </VisualStudio> + </ProjectExtensions> +</Project> \ No newline at end of file
--- a/SilverlightGlimpse/SilverlightGlimpse.csproj Sat Apr 21 21:20:05 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,131 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProductVersion>8.0.50727</ProductVersion> - <SchemaVersion>2.0</SchemaVersion> - <ProjectGuid>{BB51026B-2864-4389-AACA-0BBDF1926E46}</ProjectGuid> - <ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids> - <OutputType>Library</OutputType> - <AppDesignerFolder>Properties</AppDesignerFolder> - <RootNamespace>SilverlightGlimpse</RootNamespace> - <AssemblyName>SilverlightGlimpse</AssemblyName> - <TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier> - <TargetFrameworkVersion>v5.0</TargetFrameworkVersion> - <SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion> - <SilverlightApplication>true</SilverlightApplication> - <SupportedCultures> - </SupportedCultures> - <XapOutputs>true</XapOutputs> - <GenerateSilverlightManifest>true</GenerateSilverlightManifest> - <XapFilename>SilverlightGlimpse.xap</XapFilename> - <SilverlightManifestTemplate>Properties\AppManifest.xml</SilverlightManifestTemplate> - <SilverlightAppEntry>SilverlightGlimpse.App</SilverlightAppEntry> - <TestPageFileName>SilverlightGlimpseTestPage.html</TestPageFileName> - <CreateTestPage>true</CreateTestPage> - <ValidateXaml>true</ValidateXaml> - <EnableOutOfBrowser>false</EnableOutOfBrowser> - <OutOfBrowserSettingsFile>Properties\OutOfBrowserSettings.xml</OutOfBrowserSettingsFile> - <UsePlatformExtensions>false</UsePlatformExtensions> - <ThrowErrorsInValidation>true</ThrowErrorsInValidation> - <LinkedServerProject> - </LinkedServerProject> - </PropertyGroup> - <!-- This property group is only here to support building this project using the - MSBuild 3.5 toolset. In order to work correctly with this older toolset, it needs - to set the TargetFrameworkVersion to v3.5 --> - <PropertyGroup Condition="'$(MSBuildToolsVersion)' == '3.5'"> - <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>Bin\Debug</OutputPath> - <DefineConstants>DEBUG;TRACE;SILVERLIGHT</DefineConstants> - <NoStdLib>true</NoStdLib> - <NoConfig>true</NoConfig> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <DebugType>pdbonly</DebugType> - <Optimize>true</Optimize> - <OutputPath>Bin\Release</OutputPath> - <DefineConstants>TRACE;SILVERLIGHT</DefineConstants> - <NoStdLib>true</NoStdLib> - <NoConfig>true</NoConfig> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <ItemGroup> - <Reference Include="FloatableWindow, Version=2.0.5.0, Culture=neutral, PublicKeyToken=dd6e2c92abf74ba1, processorArchitecture=MSIL" /> - <Reference Include="mscorlib" /> - <Reference Include="System.Windows" /> - <Reference Include="system" /> - <Reference Include="System.Core" /> - <Reference Include="System.Net" /> - <Reference Include="System.Windows.Controls, Version=5.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> - <Reference Include="System.Xml" /> - <Reference Include="System.Windows.Browser" /> - </ItemGroup> - <ItemGroup> - <Compile Include="Controls\BrokenBindingsViewer.xaml.cs"> - <DependentUpon>BrokenBindingsViewer.xaml</DependentUpon> - </Compile> - <Compile Include="Controls\GlimpseViewer.xaml.cs"> - <DependentUpon>GlimpseViewer.xaml</DependentUpon> - </Compile> - <Compile Include="Controls\LoadExceptionViewer.xaml.cs"> - <DependentUpon>LoadExceptionViewer.xaml</DependentUpon> - </Compile> - <Compile Include="Controls\ExceptionsViewer.xaml.cs"> - <DependentUpon>ExceptionsViewer.xaml</DependentUpon> - </Compile> - <Compile Include="Models\BrokenBinding.cs" /> - <Compile Include="Models\ExceptionWrapper.cs" /> - <Compile Include="Properties\AssemblyInfo.cs" /> - <Compile Include="Services\GlimpseService.cs" /> - </ItemGroup> - <ItemGroup> - <Page Include="Controls\BrokenBindingsViewer.xaml"> - <SubType>Designer</SubType> - <Generator>MSBuild:Compile</Generator> - </Page> - <Page Include="Controls\GlimpseViewer.xaml"> - <SubType>Designer</SubType> - <Generator>MSBuild:Compile</Generator> - </Page> - <Page Include="Controls\LoadExceptionViewer.xaml"> - <SubType>Designer</SubType> - <Generator>MSBuild:Compile</Generator> - </Page> - <Page Include="Controls\ExceptionsViewer.xaml"> - <SubType>Designer</SubType> - <Generator>MSBuild:Compile</Generator> - </Page> - </ItemGroup> - <ItemGroup> - <None Include="Properties\AppManifest.xml" /> - </ItemGroup> - <ItemGroup> - <Content Include="Libs\FloatableWindow.dll" /> - <Content Include="Libs\System.Windows.Controls.dll" /> - </ItemGroup> - <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" /> - <!-- To modify your build process, add your task inside one of the targets below and uncomment it. - Other similar extension points exist, see Microsoft.Common.targets. - <Target Name="BeforeBuild"> - </Target> - <Target Name="AfterBuild"> - </Target> - --> - <ProjectExtensions> - <VisualStudio> - <FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}"> - <SilverlightProjectProperties /> - </FlavorProperties> - </VisualStudio> - </ProjectExtensions> -</Project> \ No newline at end of file
--- a/SilverlightGlimpse/SilverlightGlimpse.sln Sat Apr 21 21:20:05 2012 +0100 +++ b/SilverlightGlimpse/SilverlightGlimpse.sln Sun Apr 22 09:01:20 2012 +0100 @@ -1,7 +1,13 @@ Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SilverlightGlimpse", "SilverlightGlimpse.csproj", "{BB51026B-2864-4389-AACA-0BBDF1926E46}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SilverlightGlimpse", "SilverlightGlimpse\SilverlightGlimpse.csproj", "{BB51026B-2864-4389-AACA-0BBDF1926E46}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FloatableWindow", "FloatableWindow\FloatableWindow.csproj", "{D47E6045-91BB-4CD0-942F-FF015F10F7F2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SilverlightGlimpse.Test", "SilverlightGlimpse.Test\SilverlightGlimpse.Test.csproj", "{212DBD25-6C98-45EB-9974-51D04D8B6549}" +EndProject +Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Glimpse", "..\Glimpse\Glimpse.vbproj", "{C72D72F7-C49B-46DF-BD6C-0E14DBCD8F95}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -13,6 +19,18 @@ {BB51026B-2864-4389-AACA-0BBDF1926E46}.Debug|Any CPU.Build.0 = Debug|Any CPU {BB51026B-2864-4389-AACA-0BBDF1926E46}.Release|Any CPU.ActiveCfg = Release|Any CPU {BB51026B-2864-4389-AACA-0BBDF1926E46}.Release|Any CPU.Build.0 = Release|Any CPU + {D47E6045-91BB-4CD0-942F-FF015F10F7F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D47E6045-91BB-4CD0-942F-FF015F10F7F2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D47E6045-91BB-4CD0-942F-FF015F10F7F2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D47E6045-91BB-4CD0-942F-FF015F10F7F2}.Release|Any CPU.Build.0 = Release|Any CPU + {212DBD25-6C98-45EB-9974-51D04D8B6549}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {212DBD25-6C98-45EB-9974-51D04D8B6549}.Debug|Any CPU.Build.0 = Debug|Any CPU + {212DBD25-6C98-45EB-9974-51D04D8B6549}.Release|Any CPU.ActiveCfg = Release|Any CPU + {212DBD25-6C98-45EB-9974-51D04D8B6549}.Release|Any CPU.Build.0 = Release|Any CPU + {C72D72F7-C49B-46DF-BD6C-0E14DBCD8F95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C72D72F7-C49B-46DF-BD6C-0E14DBCD8F95}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C72D72F7-C49B-46DF-BD6C-0E14DBCD8F95}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C72D72F7-C49B-46DF-BD6C-0E14DBCD8F95}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse/Controls/BrokenBindingsViewer.xaml Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,9 @@ +<UserControl x:Class="SilverlightGlimpse.Controls.BrokenBindingsViewer" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> + <Grid x:Name="LayoutRoot" Background="White"> + <ScrollViewer> + <ItemsControl x:Name="icBrokenBindings" /> + </ScrollViewer> + </Grid> +</UserControl>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse/Controls/BrokenBindingsViewer.xaml.cs Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,92 @@ +using System.Reflection; +using System.Windows.Data; +using SilverlightGlimpse.Models; +using System.Windows; +using System.Diagnostics; +using System.Windows.Media; +using SilverlightGlimpse.Services; + +namespace SilverlightGlimpse.Controls +{ + public partial class BrokenBindingsViewer + { + public BrokenBindingsViewer() + { + InitializeComponent(); + } + + private void BrokenBindings_Loaded(object sender, RoutedEventArgs e) + { + this.icBrokenBindings.Items.Clear(); + LoadBrokenBindings(GlimpseService.CreateInstance.RootVisual); + } + + private void LoadBrokenBindings(UIElement uiElement) + { + var frameworkElement = uiElement as FrameworkElement; + + if (frameworkElement != null) + { + foreach (var fieldInfo in frameworkElement.GetType().GetFields(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Static)) + { + if (object.ReferenceEquals(fieldInfo.FieldType, typeof(DependencyProperty))) + { + var bindingExpression = frameworkElement.GetBindingExpression((DependencyProperty)fieldInfo.GetValue(null)); + + if (bindingExpression != null && bindingExpression.ParentBinding.Source == null && bindingExpression.ParentBinding.RelativeSource == null) + { + var isInherited = false; + + if (frameworkElement.DataContext != null && !string.IsNullOrEmpty(bindingExpression.ParentBinding.Path.Path)) + { + foreach (var propertyInfo in frameworkElement.DataContext.GetType().GetProperties(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Instance)) + { + if (string.Compare(propertyInfo.Name, bindingExpression.ParentBinding.Path.Path) == 0) + { + isInherited = true; + break; // TODO: might not be correct. Was : Exit For + } + } + } + + if (isInherited) + { + break; // TODO: might not be correct. Was : Exit For + } + + //this code handles empty bindings on the Button controls + //I'll have to look into why the Button has an empty or unresolved binding + if (string.IsNullOrEmpty(frameworkElement.Name) + && frameworkElement.GetType().Name == "TextBlock" + && fieldInfo.Name == "TextProperty" + && string.IsNullOrEmpty(bindingExpression.ParentBinding.Path.Path)) + { + break; // TODO: might not be correct. Was : Exit For + } + + BrokenBinding objBrokenBinding = new BrokenBinding( + frameworkElement.Name, + frameworkElement.GetType().Name, + fieldInfo.Name, + bindingExpression.ParentBinding.Path.Path); + this.icBrokenBindings.Items.Add(objBrokenBinding); + Debug.WriteLine("Broken Binding - ", objBrokenBinding.ToString()); + } + } + } + + int children = VisualTreeHelper.GetChildrenCount(frameworkElement); + + for (int j = 0; j <= children - 1; j++) + { + FrameworkElement child = VisualTreeHelper.GetChild(frameworkElement, j) as FrameworkElement; + + if (child != null) + { + LoadBrokenBindings(child); + } + } + } + } + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse/Controls/ExceptionsViewer.xaml Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,105 @@ +<UserControl x:Class="SilverlightGlimpse.Controls.ExceptionsViewer" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> + <Grid x:Name="LayoutRoot" Background="White"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="250" /> + <ColumnDefinition Width="*" /> + </Grid.ColumnDefinitions> + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="*" /> + <RowDefinition Height="Auto" /> + </Grid.RowDefinitions> + + <TextBlock Grid.ColumnSpan="2" + Margin="3.5" + VerticalAlignment="Center" + FontSize="18" + Foreground="Red" + Text="Exceptions Viewer" /> + + <ListBox x:Name="lbExceptions" + Grid.Row="1" + Margin="3.5" + ItemsSource="{Binding}" + SelectionChanged="lbExceptions_SelectionChanged" /> + + <ScrollViewer Grid.Row="1" + Grid.Column="1" + Margin="3.5" + DataContext="{Binding ElementName=lbExceptions, + Path=SelectedItem}"> + <Grid> + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + </Grid.RowDefinitions> + + <Rectangle Fill="BlanchedAlmond" /> + <TextBlock x:Name="tbAction" + FontSize="14" + Text="Action" + TextDecorations="Underline" /> + <TextBlock Grid.Row="1" + FontSize="11" + Text="{Binding Path=Action}" + TextWrapping="Wrap" + Visibility="{Binding ElementName=tbAction, + Path=Visibility}" /> + + <Rectangle Grid.Row="2" Fill="BlanchedAlmond" /> + <TextBlock Grid.Row="2" + Margin="0,7,0,0" + FontSize="14" + Text="Control Name" + TextDecorations="Underline" + Visibility="{Binding ElementName=tbAction, + Path=Visibility}" /> + <TextBlock Grid.Row="3" + FontSize="11" + Text="{Binding Path=ControlName}" + TextWrapping="Wrap" + Visibility="{Binding ElementName=tbAction, + Path=Visibility}" /> + + <Rectangle Grid.Row="4" Fill="BlanchedAlmond" /> + <TextBlock Grid.Row="4" + Margin="0,7,0,0" + FontSize="14" + Text="Message" + TextDecorations="Underline" /> + <TextBlock Grid.Row="5" + FontSize="11" + Text="{Binding Path=Exception.Message}" + TextWrapping="Wrap" /> + + <Rectangle Grid.Row="6" Fill="BlanchedAlmond" /> + <TextBlock Grid.Row="6" + Margin="0,7,0,0" + FontSize="14" + Text="Stack Trace" + TextDecorations="Underline" /> + <TextBlock Grid.Row="7" + FontSize="11" + Text="{Binding Path=Exception.StackTrace}" + TextWrapping="Wrap" /> + + </Grid> + </ScrollViewer> + <Button Grid.Row="2" + Grid.Column="1" + Margin="11" + HorizontalAlignment="Right" + VerticalAlignment="Center" + Click="ClearExceptions_Click" + Content="Clear Exceptions" + Padding="7" /> + </Grid> +</UserControl>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse/Controls/ExceptionsViewer.xaml.cs Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,39 @@ +using System; +using System.Windows; +using SilverlightGlimpse.Models; +using System.Windows.Controls; +using SilverlightGlimpse.Services; + +namespace SilverlightGlimpse.Controls +{ + public partial class ExceptionsViewer + { + public ExceptionsViewer() + { + InitializeComponent(); + } + + private void ClearExceptions_Click(object sender, RoutedEventArgs e) + { + GlimpseService.CreateInstance.HostExceptions.Clear(); + } + + private void ExceptionsViewer_Loaded(object sender, RoutedEventArgs e) + { + this.DataContext = GlimpseService.CreateInstance.HostExceptions; + if (GlimpseService.CreateInstance.HostExceptions.Count > 0) + this.lbExceptions.SelectedIndex = 0; + } + + private void lbExceptions_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + if (this.lbExceptions.SelectedItem != null && this.lbExceptions.SelectedItem is ExceptionWrapper) + { + if (((ExceptionWrapper)this.lbExceptions.SelectedItem).IsValidationException) + this.tbAction.Visibility = Visibility.Visible; + else + this.tbAction.Visibility = Visibility.Collapsed; + } + } + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse/Controls/GlimpseViewer.xaml Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,79 @@ +<UserControl x:Class="SilverlightGlimpse.Controls.GlimpseViewer" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:c="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" + xmlns:localc="clr-namespace:SilverlightGlimpse.Controls"> + <Grid x:Name="LayoutRoot" Background="Khaki"> + <Grid.Resources> + <SolidColorBrush x:Name="noExceptionsBrush" Color="LightGreen" /> + <SolidColorBrush x:Name="hasExceptionsBrush" Color="Red" /> + </Grid.Resources> + <Grid x:Name="layoutInstrumentPanel"> + <StackPanel Orientation="Horizontal"> + <Grid Margin="7"> + <Ellipse x:Name="elpValidationExceptions" + Width="40" + Height="40" + Fill="LightGreen" + Stroke="Brown" + StrokeThickness="2" /> + <TextBlock x:Name="tbValidationExceptions" + HorizontalAlignment="Center" + VerticalAlignment="Center" + FontSize="12" + FontWeight="Bold" + Text="0" + ToolTipService.ToolTip="Binding Exception Count" /> + </Grid> + <Grid Margin="7"> + <Ellipse x:Name="elpUnhandledExceptions" + Width="40" + Height="40" + Fill="LightGreen" + Stroke="Brown" + StrokeThickness="2" /> + <TextBlock x:Name="tbUnhandledExceptions" + HorizontalAlignment="Center" + VerticalAlignment="Center" + FontSize="12" + FontWeight="Bold" + Text="0" + ToolTipService.ToolTip="Unhandled Exception Count" /> + </Grid> + <Button x:Name="btnExpand" + Margin="7" + VerticalAlignment="Center" + Content="Expand" /> + </StackPanel> + </Grid> + <Grid x:Name="layoutViewer" Visibility="Collapsed"> + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="*" /> + </Grid.RowDefinitions> + <TextBlock Margin="3.5" + VerticalAlignment="Center" + FontSize="18" + Foreground="DarkGreen" + Text="Glimpse Viewer" /> + <Button x:Name="btnContract" + Margin="7" + HorizontalAlignment="Right" + VerticalAlignment="Center" + Content="Contract" /> + <c:TabControl Grid.Row="1" + Width="690" + Height="390" + Background="Khaki" + SelectedIndex="2"> + <c:TabItem Header="Exceptions"> + <localc:ExceptionsViewer /> + </c:TabItem> + <c:TabItem Header="Bindings with no Source"> + <localc:BrokenBindingsViewer /> + </c:TabItem> + </c:TabControl> + </Grid> + </Grid> + +</UserControl>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse/Controls/GlimpseViewer.xaml.cs Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,53 @@ +using System.Collections.Specialized; +using System.Windows; +using SilverlightGlimpse.Models; +using SilverlightGlimpse.Services; + +namespace SilverlightGlimpse.Controls +{ + public partial class GlimpseViewer + { + public GlimpseViewer() + { + InitializeComponent(); + this.DataContext = GlimpseService.CreateInstance; + GlimpseService.CreateInstance.HostExceptions.CollectionChanged += HostExceptions_CollectionChanged; + } + + private void btnContract_Click(object sender, System.Windows.RoutedEventArgs e) + { + this.layoutViewer.Visibility = Visibility.Collapsed; + } + + private void btnExpand_Click(object sender, System.Windows.RoutedEventArgs e) + { + this.layoutViewer.Visibility = Visibility.Visible; + } + + private void HostExceptions_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + int unhandledExceptionCount = 0; + int validationExceptionCount = 0; + + foreach (ExceptionWrapper ew in GlimpseService.CreateInstance.HostExceptions) + { + if (ew.IsValidationException) + validationExceptionCount++; + else + unhandledExceptionCount++; + } + + this.tbValidationExceptions.Text = validationExceptionCount.ToString(); + + this.elpValidationExceptions.Fill = validationExceptionCount == 0 + ? this.noExceptionsBrush + : this.hasExceptionsBrush; + + this.tbUnhandledExceptions.Text = unhandledExceptionCount.ToString(); + + this.elpUnhandledExceptions.Fill = unhandledExceptionCount == 0 + ? this.noExceptionsBrush + : this.hasExceptionsBrush; + } + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse/Controls/LoadExceptionViewer.xaml Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,73 @@ +<UserControl x:Class="SilverlightGlimpse.Controls.LoadExceptionViewer" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> + <Border Width="700" + Height="375" + Margin="11" + BorderBrush="SteelBlue" + BorderThickness="6" + CornerRadius="5"> + <Grid x:Name="LayoutRoot"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="200" /> + <ColumnDefinition Width="*" /> + </Grid.ColumnDefinitions> + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="*" /> + </Grid.RowDefinitions> + + <Rectangle Grid.ColumnSpan="2" Fill="SteelBlue" /> + <TextBlock x:Name="txtTitle" + Grid.ColumnSpan="2" + Margin="3.5" + VerticalAlignment="Center" + Foreground="White" + Text="Exception" /> + + <ListBox x:Name="lbExceptions" + Grid.Row="1" + Margin="3.5" + DisplayMemberPath="Message" /> + + <ScrollViewer Grid.Row="1" + Grid.Column="1" + Margin="3.5" + Background="White" + DataContext="{Binding ElementName=lbExceptions, + Path=SelectedItem}"> + <Grid> + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + </Grid.RowDefinitions> + + <TextBlock FontSize="14" + Text="Message" + TextDecorations="Underline" /> + <TextBlock Grid.Row="1" + FontSize="11" + Text="{Binding Path=Message}" + TextWrapping="Wrap" /> + + <TextBlock Grid.Row="2" + Margin="0,11,0,0" + FontSize="14" + Text="Stack Trace" + TextDecorations="Underline" /> + <TextBlock Grid.Row="3" + FontSize="11" + Text="{Binding Path=StackTrace}" + TextWrapping="Wrap" /> + + </Grid> + </ScrollViewer> + </Grid> + </Border> + +</UserControl> +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse/Controls/LoadExceptionViewer.xaml.cs Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,31 @@ +using System; +using System.Windows.Controls; + +namespace SilverlightGlimpse.Controls +{ + public partial class LoadExceptionViewer : UserControl + { + public LoadExceptionViewer() + { + InitializeComponent(); + } + + public LoadExceptionViewer(Exception e, string sourceLocation) : this() + { + this.txtTitle.Text = string.Concat("Exception ", sourceLocation.TrimStart()); + + Exception ex = e; + + while (ex != null) + { + this.lbExceptions.Items.Add(ex); + ex = ex.InnerException; + } + + if (this.lbExceptions.Items.Count > 0) + { + this.lbExceptions.SelectedIndex = 0; + } + } + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse/Models/BrokenBinding.cs Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,48 @@ +using System; + +namespace SilverlightGlimpse.Models +{ + public class BrokenBinding + { + #region Fields + + private string _controlName = string.Empty; + + #endregion + + #region Constructor + + public BrokenBinding(string controlName, string controlTypeName, string propertyName, string path) + { + _controlName = controlName; + ControlTypeName = controlTypeName; + PropertyName = propertyName; + Path = path; + } + + #endregion + + #region Properties + + public string ControlName { get { return string.IsNullOrEmpty(_controlName) ? "(none)" : _controlName; } } + public string ControlTypeName { get; private set; } + public string Path { get; private set; } + public string PropertyName { get; private set; } + + #endregion + + #region Methods + + public override string ToString() + { + return string.Format( + "Control Name: {0}, Type: {1}, Property: {2}, Path: {3}", + this.ControlName, + this.ControlTypeName, + this.PropertyName, + this.Path); + } + + #endregion + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse/Models/ExceptionWrapper.cs Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,51 @@ +using System; +using System.Windows.Controls; + +namespace SilverlightGlimpse.Models +{ + public class ExceptionWrapper + { + #region Fields + + private ValidationErrorEventAction _enumAction = ValidationErrorEventAction.Added; + + #endregion + + #region Constructor + + public ExceptionWrapper(Exception e) + { + Exception = e; + } + + #endregion + + #region Properties + + public ExceptionWrapper(ValidationErrorEventAction enumAction, string controlName, Exception validationException) + { + _enumAction = enumAction; + ControlName = controlName; + Exception = validationException; + IsValidationException = true; + } + + public ValidationErrorEventAction Action { get { return _enumAction; } } + public string ControlName { get; private set; } + public Exception Exception { get; private set; } + public bool IsValidationException { get; private set; } + + #endregion + + #region Methods + + public override string ToString() + { + return IsValidationException + ? string.Format("({0}) - {1}", this.Action, Exception.Message) + : Exception.Message; + } + + #endregion + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse/Properties/AppManifest.xml Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,6 @@ +<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" +> + <Deployment.Parts> + </Deployment.Parts> +</Deployment>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse/Properties/AssemblyInfo.cs Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SilverlightGlimpse")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SilverlightGlimpse")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("52ef33ca-e923-41ef-a7c8-98ec475bc956")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse/Services/GlimpseService.cs Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,124 @@ +using System; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Windows; +using System.Windows.Controls; +using SilverlightGlimpse.Controls; +using SilverlightGlimpse.Models; +using System.Windows.Media; + +namespace SilverlightGlimpse.Services +{ + public class GlimpseService + { + #region Fields + + private static GlimpseService _instance; + + #endregion + + #region Private constructor + + private GlimpseService() + { + HostExceptions = new ObservableCollection<ExceptionWrapper>(); + } + + #endregion + + #region Properties + + public static GlimpseService CreateInstance + { + get { return (_instance == null) ? _instance = new GlimpseService() : _instance; } + } + + internal Application App { get; private set; } + internal FloatableWindow GlimpseWindow { get; set;} + internal string HostApplicationName { get; set; } + internal ObservableCollection<ExceptionWrapper> HostExceptions { get; private set; } + internal FrameworkElement RootVisual { get; private set; } + + #endregion + + #region Creation and Loading + + public void DisplayLoadFailure(Application app, Exception ex) + { + string source = ex.StackTrace.Substring(0, ex.StackTrace.IndexOf(Environment.NewLine)); + Debug.WriteLine("{0} had exception. {1}", this.HostApplicationName, ex.ToString()); + App = app; + App.RootVisual = new LoadExceptionViewer(ex, source); + } + + public void Load(Application app, string hostApplicationName) + { + this.App = app; + this.RootVisual = App.RootVisual as FrameworkElement; + this.HostApplicationName = hostApplicationName; + + RootVisual.BindingValidationError += HostRootVisual_BindingValidationError; + App.UnhandledException += Application_UnhandledException; + + FloatableWindow window = new FloatableWindow(); + window.Title = this.HostApplicationName; + window.Content = new GlimpseViewer(); + window.ParentLayoutRoot = (Panel)VisualTreeHelper.GetChild(RootVisual, 0); ; + + if (Double.IsNaN(RootVisual.Width)) + { + //if the host control is autosized (consumes the browser window) then locate Glimpse in the top, left + window.Show(); + } + else + { + //if the host is fixed size then attempt to locate the popup control in the upper right corner + var dblLeft = RootVisual.Width - 200; + + if (dblLeft < 0) + dblLeft = 0; + + window.Show(dblLeft,10); + } + } + #endregion + + #region Events handlers + + private void HostRootVisual_BindingValidationError(object sender, ValidationErrorEventArgs e) + { + string controlName = "(none)"; + Control control = e.OriginalSource as Control; + + if (control != null && !string.IsNullOrEmpty(control.Name)) + { + controlName = control.Name; + } + + Exception ex = e.Error.Exception; + + while (ex != null) + { + this.HostExceptions.Add(new ExceptionWrapper(e.Action, controlName, e.Error.Exception)); + ex = ex.InnerException; + } + } + + private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) + { + Debug.WriteLine("{0} had exception. {1}", this.HostApplicationName, e.ExceptionObject.ToString()); + + Exception ex = e.ExceptionObject; + + while (ex != null) + { + this.HostExceptions.Add(new ExceptionWrapper(ex)); + ex = ex.InnerException; + } + + e.Handled = true; + } + + #endregion + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse/SilverlightGlimpse.csproj Sun Apr 22 09:01:20 2012 +0100 @@ -0,0 +1,134 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProductVersion>8.0.50727</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{BB51026B-2864-4389-AACA-0BBDF1926E46}</ProjectGuid> + <ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>SilverlightGlimpse</RootNamespace> + <AssemblyName>SilverlightGlimpse</AssemblyName> + <TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier> + <TargetFrameworkVersion>v5.0</TargetFrameworkVersion> + <SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion> + <SilverlightApplication>true</SilverlightApplication> + <SupportedCultures> + </SupportedCultures> + <XapOutputs>true</XapOutputs> + <GenerateSilverlightManifest>true</GenerateSilverlightManifest> + <XapFilename>SilverlightGlimpse.xap</XapFilename> + <SilverlightManifestTemplate>Properties\AppManifest.xml</SilverlightManifestTemplate> + <SilverlightAppEntry>SilverlightGlimpse.App</SilverlightAppEntry> + <TestPageFileName>SilverlightGlimpseTestPage.html</TestPageFileName> + <CreateTestPage>true</CreateTestPage> + <ValidateXaml>true</ValidateXaml> + <EnableOutOfBrowser>false</EnableOutOfBrowser> + <OutOfBrowserSettingsFile>Properties\OutOfBrowserSettings.xml</OutOfBrowserSettingsFile> + <UsePlatformExtensions>false</UsePlatformExtensions> + <ThrowErrorsInValidation>true</ThrowErrorsInValidation> + <LinkedServerProject> + </LinkedServerProject> + </PropertyGroup> + <!-- This property group is only here to support building this project using the + MSBuild 3.5 toolset. In order to work correctly with this older toolset, it needs + to set the TargetFrameworkVersion to v3.5 --> + <PropertyGroup Condition="'$(MSBuildToolsVersion)' == '3.5'"> + <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>Bin\Debug</OutputPath> + <DefineConstants>DEBUG;TRACE;SILVERLIGHT</DefineConstants> + <NoStdLib>true</NoStdLib> + <NoConfig>true</NoConfig> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>Bin\Release</OutputPath> + <DefineConstants>TRACE;SILVERLIGHT</DefineConstants> + <NoStdLib>true</NoStdLib> + <NoConfig>true</NoConfig> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="mscorlib" /> + <Reference Include="System.Windows" /> + <Reference Include="system" /> + <Reference Include="System.Core" /> + <Reference Include="System.Net" /> + <Reference Include="System.Windows.Controls, Version=5.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\Libs\System.Windows.Controls.dll</HintPath> + </Reference> + <Reference Include="System.Xml" /> + <Reference Include="System.Windows.Browser" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Controls\BrokenBindingsViewer.xaml.cs"> + <DependentUpon>BrokenBindingsViewer.xaml</DependentUpon> + </Compile> + <Compile Include="Controls\GlimpseViewer.xaml.cs"> + <DependentUpon>GlimpseViewer.xaml</DependentUpon> + </Compile> + <Compile Include="Controls\LoadExceptionViewer.xaml.cs"> + <DependentUpon>LoadExceptionViewer.xaml</DependentUpon> + </Compile> + <Compile Include="Controls\ExceptionsViewer.xaml.cs"> + <DependentUpon>ExceptionsViewer.xaml</DependentUpon> + </Compile> + <Compile Include="Models\BrokenBinding.cs" /> + <Compile Include="Models\ExceptionWrapper.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="Services\GlimpseService.cs" /> + </ItemGroup> + <ItemGroup> + <Page Include="Controls\BrokenBindingsViewer.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> + <Page Include="Controls\GlimpseViewer.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> + <Page Include="Controls\LoadExceptionViewer.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> + <Page Include="Controls\ExceptionsViewer.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> + </ItemGroup> + <ItemGroup> + <None Include="Properties\AppManifest.xml" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\FloatableWindow\FloatableWindow.csproj"> + <Project>{D47E6045-91BB-4CD0-942F-FF015F10F7F2}</Project> + <Name>FloatableWindow</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> + <ProjectExtensions> + <VisualStudio> + <FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}"> + <SilverlightProjectProperties /> + </FlavorProperties> + </VisualStudio> + </ProjectExtensions> +</Project> \ No newline at end of file