Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6588417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:02:44+00:00 2026-05-25T17:02:44+00:00

I’ve a CustomControl which use a ScrollViewer. The following code is an example which

  • 0

I’ve a CustomControl which use a ScrollViewer. The following code is an example which shows my use case in an easy way:

<Style TargetType="controls:MyCustomControl">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="controls:MyCustomControl">
        <Grid x:Name="LayoutRoot" Background="White">
          <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="20"/>
            <RowDefinition Height="20"/>
          </Grid.RowDefinitions>
          <ScrollViewer x:Name="scrollViewer" Grid.Row="0"
                        Height="300" Width="400"
                        VerticalScrollBarVisibility="Auto" 
                        HorizontalScrollBarVisibility="Auto"
                        Style="{StaticResource ScrollViewerStyle}">
            <Canvas x:Name="outer" Width="400" Height="400"
                    Background="Red" Margin="50">
              <Canvas x:Name="inner" Background="Green" 
                      Width="400" Height="400">
                <Canvas.RenderTransform>
                  <ScaleTransform ScaleX="{Binding Value, ElementName=slider}"
                                  ScaleY="{Binding Value, ElementName=slider}"/>
                </Canvas.RenderTransform>
              </Canvas>
            </Canvas>
          </ScrollViewer>
        <Slider x:Name="slider" Minimum="0.1" Maximum ="10"
                Value="1" Grid.Row="2"/>
      </Grid>
    </ControlTemplate>
  </Setter.Value>
</Setter>

I left out the nonrelevant CodeBehind belonging to Slider.ValueChanged.

In a further question I ask How do I stick Controls inside of ScrollViewer. In this answer I got the idea to template the ScrollViewer. I added some elements to the ScrollViewer as shown in the answer. For example I’ve a new Canvas inside of my ScrollViewer:

<Canvas x:Name="canvas"/>

I need access to this Canvas at runtime, so in WPF I created:

public class MyScrollViewer : ScrollViewer

I override OnApplyTemplate and get access to it via GetTemplateChild. So all done.

In SL this way is not possible since ScrollViewer is sealed.

Now I am looking for an other way to get access. I hoped VisualTreeHelper would help me, but I do not get the Canvas. Neither in CodeBehind of my custom control nor in the codebehind of my MainPage (where I use my control).

private void GetCanvas(DependencyObject dependencyObject)
  {
    int count = VisualTreeHelper.GetChildrenCount(dependencyObject);
    for (int i = 0; i < count; i++)
    {
      DependencyObject child = VisualTreeHelper.GetChild(dependencyObject);
      Canvas canvas = child as Canvas;
      if (canvas == null)
      {
        GetCanvas(child);
      }
      else
      {
        // Code here if found
      }
    }
  }

Then a colleague remember me, that there exists the directive x:FieldModifier. I never used it before, just heard about it. I give it a try.

x:FieldModifier="public"

But no idea if it really give me the possibility to access from codebehind, even less how.

So, is there any way how I could access at my Canvas at runtime in Silverlight? Maybe there is maybe another solution in WPF itself, which also works on SL?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:02:45+00:00Added an answer on May 25, 2026 at 5:02 pm

    In Silverlight, this is possible using the extension method GetVisualDescendants(DependencyObject) in the Silverlight toolkit. The following should work…

    • Add a reference to System.Windows.Controls.Primitives
    • Add using System.Windows.Controls.Primitives
    • Call scrollViewer.GetVisualDescendants().OfType().FirstOrDefault(canvas => canvas.Name.Equals(“yourCanvasName”)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
i got an object with contents of html markup in it, for example: string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.