Skip to content

Commit

Permalink
Merge branch 'Bring_intoView'
Browse files Browse the repository at this point in the history
  • Loading branch information
John Simons committed Jun 8, 2016
2 parents 2e740c7 + 270c09e commit 2b3d529
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 4 deletions.
61 changes: 61 additions & 0 deletions src/ServiceControl.Config/Extensions/VisualTreeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
namespace ServiceControl.Config.Extensions
{
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

public static class VisualTreeExtensions
{
public static Control FindControlWithError(this DependencyObject parent)
{
// Confirm parent and childName are valid.
if (parent == null)
{
return null;
}

Control foundChild = null;

var childrenCount = VisualTreeHelper.GetChildrenCount(parent);
for (var i = 0; i < childrenCount; i++)
{
var child = VisualTreeHelper.GetChild(parent, i);
// If the child is not of the request child type child
var childType = child;
if (childType == null)
{
// recursively drill down the tree
foundChild = FindControlWithError(child);

// If the child is found, break so we do not overwrite the found child.
if (foundChild != null)
{
break;
}
}
else
{
var frameworkElement = child as FrameworkElement;

// If the child is in error
if (frameworkElement != null && Validation.GetHasError(frameworkElement))
{
foundChild = (Control)child;
break;
}

// recursively drill down the tree
foundChild = FindControlWithError(child);

// If the child is found, break so we do not overwrite the found child.
if (foundChild != null)
{
break;
}
}
}

return foundChild;
}
}
}
11 changes: 11 additions & 0 deletions src/ServiceControl.Config/Framework/WindowManagerEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace ServiceControl.Config.Framework
{
using ServiceControl.Config.Extensions;

public interface IWindowManagerEx : IWindowManager
{
void NavigateTo(RxScreen screen, object context = null, IDictionary<string, object> settings = null);
Expand All @@ -24,6 +26,8 @@ public interface IWindowManagerEx : IWindowManager
bool ShowSliderDialog(SliderDialogViewModel viewModel);

bool ShowActionReport(ReportCard reportcard, string title, string errorsMessage, string warningsMessage);

void ScrollFirstErrorIntoView(object viewModel, object context = null);
}

class WindowManagerEx : WindowManager, IWindowManagerEx
Expand Down Expand Up @@ -105,6 +109,13 @@ public bool ShowActionReport(ReportCard reportcard, string title, string errorsM
return result ?? false;
}

public void ScrollFirstErrorIntoView(object viewModel, object context = null)
{
var view = ViewLocator.LocateForModel(viewModel, null, context);
var controlInError = view?.FindControlWithError();
controlInError?.BringIntoView();
}

private ShellViewModel GetShell()
{
var shell = Application.Current.MainWindow.DataContext as ShellViewModel;
Expand Down
1 change: 1 addition & 0 deletions src/ServiceControl.Config/ServiceControl.Config.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<Compile Include="Extensions\DeactivateExtensions.cs" />
<Compile Include="Extensions\StringExtensions.cs" />
<Compile Include="Extensions\ValidatorExtensions.cs" />
<Compile Include="Extensions\VisualTreeExtensions.cs" />
<Compile Include="Framework\Commands\AwaitableAbstractCommand.cs" />
<Compile Include="Framework\IProgressViewModel.cs" />
<Compile Include="Framework\Modules\InstallerModule.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ private async Task Add(object arg)
{
viewModel.NotifyOfPropertyChange(string.Empty);
viewModel.SubmitAttempted = false;
windowManager.ScrollFirstErrorIntoView(viewModel);

return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ async Task Save(object arg)
{
viewModel.NotifyOfPropertyChange(string.Empty);
viewModel.SubmitAttempted = false;
windowManager.ScrollFirstErrorIntoView(viewModel);

return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
<RowDefinition Height="auto" />
</Grid.RowDefinitions>

<ScrollViewer IsTabStop="False">
<ScrollViewer x:Name="ContentScroller" IsTabStop="False">
<ContentPresenter Content="{Binding SharedContent, ElementName=uc}" />
</ScrollViewer>

<Border x:Name="progressOverlay"
Grid.RowSpan="2"
<Border Grid.RowSpan="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="#CCFFFFFF"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ namespace ServiceControl.Config.UI.SharedInstanceEditor
{
public partial class SharedInstanceEditorView
{

public SharedInstanceEditorView()
{
InitializeComponent();
}

public string SaveText
{
get { return (string)GetValue(SaveTextProperty); }
get { return (string) GetValue(SaveTextProperty); }
set { SetValue(SaveTextProperty, value); }
}

Expand Down

0 comments on commit 2b3d529

Please sign in to comment.