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 7648363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:41:50+00:00 2026-05-31T10:41:50+00:00

I am having a very difficult time setting up a binding which I think

  • 0

I am having a very difficult time setting up a binding which I think should be easy. Help is greatly appreciated.

I have a resource dictionary named FormResource.xaml. In this dictionary contains a Style for the ScrollView that I redine the template for. The purpose is I want a wider vertical scrollbar on it.

<Style x:Key="LargeScrolling" TargetType="ScrollViewer">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ScrollViewer">
                <Grid Background="{TemplateBinding Background}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <ScrollContentPresenter x:Name="ScrollContentPresenter"
                            Margin="{TemplateBinding Padding}"
                            ContentTemplate="{TemplateBinding ContentTemplate}"/>
                    <ScrollBar x:Name="PART_VerticalScrollBar" 
                            Style="{StaticResource LargeVerticalScrollBar}" 
                            Width="{Binding ElementName=MDTForm, Path=ScrollBarWidth}"
                            IsTabStop="False"
                            Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                            Grid.Column="1" Grid.Row="0" Orientation="Vertical"
                            ViewportSize="{TemplateBinding ViewportHeight}"
                            Maximum="{TemplateBinding ScrollableHeight}"
                            Minimum="0"
                            Value="{TemplateBinding VerticalOffset}"
                            Margin="0,-1,-1,-1"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

I have a UserControl named FormControl.

public class FormControl : UserControl

I used to have this as a partial class with a XAML componenet, in which what I am trying to do worked, but I had to remove the XAML since I derive from this class in another assembly and WPF does not allow you to derive from a partial class in another assembly.

In FormControl I define a ScrollBarWidth property.

    public static readonly DependencyProperty ScrollBarWidthProperty = DependencyProperty.Register("ScrollBarWidth", typeof(double), typeof(FormControl));
    public double ScrollBarWidth
    {
        get { return (double)base.GetValue(ScrollBarWidthProperty); }
        set { base.SetValue(ScrollBarWidthProperty, value); }
    }

When I had this as a partial class in the main declaration I gave the FormControl class a Name of MDTForm, which is what I am using as the ElementName in my binding. I tried registering this name in FormClass.cs but no matter what I do the scrollbar is not picking up the property value.

Here is where I create my ScrollViewer in the FormControl class.

        _canvasScrollViewer = new ScrollViewer();
        _canvasScrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
        _canvasScrollViewer.VerticalAlignment = VerticalAlignment.Top;
        _canvasScrollViewer.MaxHeight = Constants.ScrollViewMaxHeight;
        _canvasScrollViewer.Style = (Style)FindResource("LargeScrolling");

The only way that I got this to work was to bind to a static property. I used this for the binding.

Width="{Binding Source={x:Static form:FormControl.ScrollBarWidthP}}"

Then defined the property as such.

public static double ScrollBarWidth { get; set; }

However, I don’t want this as I can have multiple FormControl objects loaded at the same time and they may not all have the same scroll bar width property.

  • 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-31T10:41:51+00:00Added an answer on May 31, 2026 at 10:41 am

    Use a RelativeSource Binding instead of ElementName:

    {Binding RelativeSource={RelativeSource Mode=FindAncestor,
             AncestorType={x:Type controls:FormControl}}, Path=ScrollBarWidth}
    

    This will walk up the visual tree at runtime to find the parent control containing the ScrollViewer, which solves both your scoping and multiple instance issues.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having a very difficult time editing my .htaccess file to do
I am very new to Orchard, and am having a most difficult time setting
I am using MYSQL Server version: 5.5.16 and having a very difficult time establishing
I am having a very difficult time handling null returns in DB2. I've tried
I'm trying to learn LINQ to SQL but having a very difficult time. I
I'm having a very difficult time debugging a problem with an application I've been
I'm having a very difficult time trying to figure out how to make my
I'm having a difficult time getting answers to a few very basic PHP questions.
So, I am having a very difficult time explaining my problem, I hope this
I'm having a very difficult time understanding how a c# form can populate and

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.