Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic ScrollViewer Automation Properties (Read 67 times)
Patryk
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 16
Joined: Jun 13th, 2025
ScrollViewer Automation Properties
Mar 3rd, 2026 at 12:31pm
Print Post  
Hello,

I am using the ScrollViewer that is builded in your DiagramView.
I am wondering how to assign automation properties for the scroll view (and if possible separately for horizontal and vertical one).

Do you have any solution?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: ScrollViewer Automation Properties
Reply #1 - Mar 3rd, 2026 at 1:29pm
Print Post  
Hi,

You could set them from Xaml if you redefine both DiagramView and ScrollViewer template. Otherwise you could access them by overriding OnApplyTemplate in child class:

Code
Select All
public class DiagramViewEx : DiagramView
{
    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();

        var scrollViewer = GetTemplateChild("PART_ScrollViewer") as ScrollViewer;
        if (scrollViewer != null)
        {
            scrollViewer.ApplyTemplate();

            var horizontal = scrollViewer.Template.FindName(
                "PART_HorizontalScrollBar", scrollViewer) as ScrollBar;
            var vertical = scrollViewer.Template.FindName(
                "PART_VerticalScrollBar", scrollViewer) as ScrollBar;

            if (horizontal != null)
                AutomationProperties.SetAutomationId(horizontal, "HorizontalScroll");
            if (vertical != null)
                AutomationProperties.SetAutomationId(vertical, "VerticalScroll");
        }
    }
} 



If you prefer Xaml and redefining templates, here's DiagramView's one:

Code
Select All
<!-- DiagramView -->
<Style TargetType="{x:Type local:DiagramView}">
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:DiagramView}">
                <ScrollViewer
                    x:Name="PART_ScrollViewer"
                    CanContentScroll="True"
                    HorizontalScrollBarVisibility="Auto"
                    Focusable="False">

                    <local:DiagramPresenter x:Name="PART_Presenter"
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>

                </ScrollViewer>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style> 



I'm seeing this as ScrollViewer template after selecting Edit Template command in VS designer:

Code
Select All
<ControlTemplate x:Key="ScrollViewerTemplate1" TargetType="{x:Type ScrollViewer}">
    <Grid x:Name="Grid" Background="{TemplateBinding Background}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Rectangle x:Name="Corner" Grid.Column="1" Fill="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Grid.Row="1"/>
        <ScrollContentPresenter x:Name="PART_ScrollContentPresenter" CanHorizontallyScroll="False" ContentTemplate="{TemplateBinding ContentTemplate}" CanVerticallyScroll="False" Grid.Column="0" Content="{TemplateBinding Content}" CanContentScroll="{TemplateBinding CanContentScroll}" Margin="{TemplateBinding Padding}" Grid.Row="0"/>
        <ScrollBar x:Name="PART_VerticalScrollBar" AutomationProperties.AutomationId="VerticalScrollBar" Cursor="Arrow" Grid.Column="1" Maximum="{TemplateBinding ScrollableHeight}" Minimum="0" Grid.Row="0" Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource Mode=TemplatedParent}}" ViewportSize="{TemplateBinding ViewportHeight}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
        <ScrollBar x:Name="PART_HorizontalScrollBar" AutomationProperties.AutomationId="HorizontalScrollBar" Cursor="Arrow" Grid.Column="0" Maximum="{TemplateBinding ScrollableWidth}" Minimum="0" Orientation="Horizontal" Grid.Row="1" Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource Mode=TemplatedParent}}" ViewportSize="{TemplateBinding ViewportWidth}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
    </Grid>
</ControlTemplate>
 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Patryk
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 16
Joined: Jun 13th, 2025
Re: ScrollViewer Automation Properties
Reply #2 - Mar 4th, 2026 at 10:10am
Print Post  
Slavcho wrote on Mar 3rd, 2026 at 1:29pm:
Hi,

You could set them from Xaml if you redefine both DiagramView and ScrollViewer template. Otherwise you could access them by overriding OnApplyTemplate in child class:

Code
Select All
public class DiagramViewEx : DiagramView
{
    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();

        var scrollViewer = GetTemplateChild("PART_ScrollViewer") as ScrollViewer;
        if (scrollViewer != null)
        {
            scrollViewer.ApplyTemplate();

            var horizontal = scrollViewer.Template.FindName(
                "PART_HorizontalScrollBar", scrollViewer) as ScrollBar;
            var vertical = scrollViewer.Template.FindName(
                "PART_VerticalScrollBar", scrollViewer) as ScrollBar;

            if (horizontal != null)
                AutomationProperties.SetAutomationId(horizontal, "HorizontalScroll");
            if (vertical != null)
                AutomationProperties.SetAutomationId(vertical, "VerticalScroll");
        }
    }
} 



If you prefer Xaml and redefining templates, here's DiagramView's one:

Code
Select All
<!-- DiagramView -->
<Style TargetType="{x:Type local:DiagramView}">
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:DiagramView}">
                <ScrollViewer
                    x:Name="PART_ScrollViewer"
                    CanContentScroll="True"
                    HorizontalScrollBarVisibility="Auto"
                    Focusable="False">

                    <local:DiagramPresenter x:Name="PART_Presenter"
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>

                </ScrollViewer>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style> 



I'm seeing this as ScrollViewer template after selecting Edit Template command in VS designer:

Code
Select All
<ControlTemplate x:Key="ScrollViewerTemplate1" TargetType="{x:Type ScrollViewer}">
    <Grid x:Name="Grid" Background="{TemplateBinding Background}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Rectangle x:Name="Corner" Grid.Column="1" Fill="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Grid.Row="1"/>
        <ScrollContentPresenter x:Name="PART_ScrollContentPresenter" CanHorizontallyScroll="False" ContentTemplate="{TemplateBinding ContentTemplate}" CanVerticallyScroll="False" Grid.Column="0" Content="{TemplateBinding Content}" CanContentScroll="{TemplateBinding CanContentScroll}" Margin="{TemplateBinding Padding}" Grid.Row="0"/>
        <ScrollBar x:Name="PART_VerticalScrollBar" AutomationProperties.AutomationId="VerticalScrollBar" Cursor="Arrow" Grid.Column="1" Maximum="{TemplateBinding ScrollableHeight}" Minimum="0" Grid.Row="0" Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource Mode=TemplatedParent}}" ViewportSize="{TemplateBinding ViewportHeight}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
        <ScrollBar x:Name="PART_HorizontalScrollBar" AutomationProperties.AutomationId="HorizontalScrollBar" Cursor="Arrow" Grid.Column="0" Maximum="{TemplateBinding ScrollableWidth}" Minimum="0" Orientation="Horizontal" Grid.Row="1" Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource Mode=TemplatedParent}}" ViewportSize="{TemplateBinding ViewportWidth}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
    </Grid>
</ControlTemplate>
 



Regards,
Slavcho
Mindfusion


Ive tried and its still not visible via tools like Snoop or Accessibility Insights for Windows.

Ive tried to set different ids for automation and the tools cant be found.
The information was lost after the update to 4> mindfusion version :/
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: ScrollViewer Automation Properties
Reply #3 - Mar 4th, 2026 at 10:54am
Print Post  
Hi,

Maybe you were seeing it from external ScrollViewer in older version.

DiagramView overrides OnCreateAutomationPeer since v4.1.6, to allow enumerating non-realized items. If you don't care about that, try overriding OnCreateAutomationPeer yourself to return the base FrameworkElementAutomationPeer, and hopefully it could find ScrollViewer from template and return its peer.

Our DiagramViewAutomationPeer returns ScrollViewer's peer too when requested via Scroll patternInterface:

Code
Select All
override public object GetPattern(PatternInterface patternInterface)
{
	if (patternInterface == PatternInterface.Scroll)
	{
		if (View.ScrollViewer != null)
		{
			var scrollPeer = CreatePeerForElement(View.ScrollViewer);
			if (scrollPeer != null && scrollPeer is IScrollProvider)
			{
				scrollPeer.EventsSource = this;
				return (IScrollProvider)scrollPeer;
			}
		}
	}
... 



so maybe check if you can configure your tools to request that PatternInterface.

Let us know if still not working and our developer will debug using these tools.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint