Are allowed scrollbars possible?

I am having trouble trying to create ScrollBars/ScrollViewers permanent access. I am working on a data entry application where some users may only have read permissions. To do this, disable all controls so that they do not make any changes.

When the control is disabled, the user cannot view all the information in the scrollable controls (Infragistics XamDataGrid , DevExpress GridControl , TextBox es with Wrap, ListBox , etc.). I was hoping I could outsmart Microsoft and implement Trigger to set IsEnabled to true when it was set to false, but of course it didn't work (for various reasons, I'm sure).

At the moment, I focus strictly on the text field to try to disable the content, but I support ScrollViewer and no luck.

I was hoping there could be a solution, I.E. Overriding the IsEnabled dependency property of a ScrollViewer always returns true or provides some type of Style that prevents ScrollViewer .

I know that TextBox has IsReadOnly property, but it is useless for many other controls that I need to solve this problem.

Is there a way to solve this in a fairly simple way (just as in that I can make a style that applies everywhere without changing files with code over 200+).

thanks

EDIT: Here is the code I'm using in a sample project to try and solve this problem.

 <Window x:Class="WPFScrollViewerStyles.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <Style BasedOn="{x:Null}" TargetType="{x:Type TextBox}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type TextBox}"> <Microsoft_Windows_Themes:ListBoxChrome x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderFocused="{TemplateBinding IsKeyboardFocusWithin}" SnapsToDevicePixels="true"> <ScrollViewer x:Name="PART_ContentHost" HorizontalScrollBarVisibility="Visible" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" IsEnabled="True" /> </Microsoft_Windows_Themes:ListBoxChrome> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="false"> <Setter Property="IsEnabled" Value="True" TargetName="PART_ContentHost" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <Grid IsEnabled="False"> <Grid.ColumnDefinitions> <ColumnDefinition Width="100" /> <ColumnDefinition Width="100" /> <ColumnDefinition Width="100" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="100" /> <RowDefinition Height="100" /> <RowDefinition Height="100" /> </Grid.RowDefinitions> <TextBox x:Name="txtScroller" Width="100" Height="100" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap" ScrollViewer.CanContentScroll="True"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras faucibus hendrerit lorem, auctor vehicula sem molestie nec. Quisque non massa quam. Nullam tempor blandit tempor. Integer in molestie ipsum. Donec augue mi, auctor vitae scelerisque a, vehicula ac ipsum. Etiam posuere vulputate augue quis convallis. Nullam aliquet purus nec lacus fermentum hendrerit egestas purus tincidunt. Suspendisse quis lacinia libero. Quisque facilisis turpis at augue dignissim aliquam ultrices sem porta. Etiam sagittis arcu id nibh ultrices dictum. Nulla non lectus luctus est malesuada luctus. Praesent sed lobortis nisi. Morbi et porttitor massa. Sed pellentesque, nisl eu imperdiet varius, ligula augue cursus nisl, eu egestas metus velit non elit. Phasellus elementum hendrerit risus, eu tincidunt ante gravida vel. </TextBox> <ListBox x:Name="lstScroller" Width="100" Height="100" Grid.Column="1"> <ListBox.Items> <ListBoxItem Content="Item 1" /> <ListBoxItem Content="Item 2" /> <ListBoxItem Content="Item 3" /> <ListBoxItem Content="Item 4" /> <ListBoxItem Content="Item 5" /> <ListBoxItem Content="Item 6" /> <ListBoxItem Content="Item 7" /> <ListBoxItem Content="Item 8" /> <ListBoxItem Content="Item 9" /> <ListBoxItem Content="Item 10" /> <ListBoxItem Content="Item 11" /> <ListBoxItem Content="Item 12" /> <ListBoxItem Content="Item 13" /> <ListBoxItem Content="Item 14" /> <ListBoxItem Content="Item 15" /> </ListBox.Items> </ListBox> </Grid> 

+4
source share
3 answers

Thanks to Cedric Dussud at Microsoft, I found a solution.

For reference: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/3bf5e186-845c-4b63-acd9-17d294a30f77

Instead of subclassing the ScrollViewer control, I override the metadata in the Application_Startup event of the application, for example:

 ScrollViewer.IsEnabledProperty.OverrideMetadata(typeof(ScrollViewer), new UIPropertyMetadata(true, new PropertyChangedCallback(ScrollViewer_IsEnabledPropertyChanged), new CoerceValueCallback(ScrollViewerForceEnabled))); 

Then I process CoerceValueCallback to always return true, for example:

  private static void ScrollViewer_IsEnabledPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs args) { } private static object ScrollViewerForceEnabled(DependencyObject source, object value) { return true; } 

According to Cedric, this may have unforeseen consequences, but at the moment (and my powerful test application with the grid turned off and two scrollable controls) I have not found it. Hope this solution can help someone else, no problem.

+5
source

I know this is an old question, but I think I found a similar, but simpler solution that may help others: instead of overriding propertyt metadata for ScrollViewer IsEnabledProperty, I applied the same approach initially, but to ScrollBar IsEnabledProperty, This seems to work fine and doesn't require me to create and apply a new template to view the scroll. The only way back seems to be that the mouse keyboard and page up / down commands do not work (since the scroll view itself is still disabled). Override metadata code:

 ScrollBar.IsEnabledProperty.OverrideMetadata( typeof(ScrollBar), new FrameworkPropertyMetadata( (PropertyChangedCallback) null, (CoerceValueCallback) AlwaysCoerceToTrue)); 

and AlwaysCoerceToTrue method:

 private static object AlwaysCoerceToTrue(DependencyObject o, object value) { return true; } 
+2
source

I think that you can restore the user interface elements by forcing them to use a control template that includes

 <ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" ... /> 

For example, for a TextBox you can use the modified default control template :

 <ControlTemplate TargetType="{x:Type TextBoxBase}"> <Border Name="Border" CornerRadius="2" Padding="2" BorderThickness="1"> ... <ScrollViewer Margin="0" x:Name="PART_ContentHost" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible"/> <!-- HERE --> </Border> </ControlTemplate> 
0
source

Source: https://habr.com/ru/post/1341727/


All Articles