Implement ScrollContainerProperty to allow plugins to disable the default scrollviewer wrapper on their controls

This commit is contained in:
Brant Martin
2019-05-08 18:34:09 -04:00
parent de12327ac2
commit 91ceb0aa22
3 changed files with 28 additions and 1 deletions

View File

@@ -272,6 +272,7 @@
<Compile Include="Views\Entities\CharacterView.xaml.cs"> <Compile Include="Views\Entities\CharacterView.xaml.cs">
<DependentUpon>CharacterView.xaml</DependentUpon> <DependentUpon>CharacterView.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Views\Extensions.cs" />
<Compile Include="Views\ModListControl.xaml.cs"> <Compile Include="Views\ModListControl.xaml.cs">
<DependentUpon>ModListControl.xaml</DependentUpon> <DependentUpon>ModListControl.xaml</DependentUpon>
</Compile> </Compile>

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace Torch.Server.Views
{
public static class Extensions
{
public static readonly DependencyProperty ScrollContainerProperty = DependencyProperty.RegisterAttached("ScrollContainer", typeof(bool), typeof(Extensions), new PropertyMetadata(true));
public static bool GetScrollContainer(this UIElement ui)
{
return (bool)ui.GetValue(ScrollContainerProperty);
}
public static void SetScrollContainer(this UIElement ui, bool value)
{
ui.SetValue(ScrollContainerProperty, value);
}
}
}

View File

@@ -41,7 +41,9 @@ namespace Torch.Server.Views
{ {
if (propertyChangedEventArgs.PropertyName == nameof(PluginManagerViewModel.SelectedPlugin)) if (propertyChangedEventArgs.PropertyName == nameof(PluginManagerViewModel.SelectedPlugin))
{ {
if (((PluginManagerViewModel)DataContext).SelectedPlugin.Control is PropertyGrid) var plugin = ((PluginManagerViewModel)DataContext).SelectedPlugin;
if (plugin.Control is PropertyGrid || !plugin.Control.GetScrollContainer())
PScroll.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled; PScroll.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled;
else else
PScroll.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; PScroll.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;