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:
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:
<!-- 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:
<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