Solved

WPF - External data binding to controls inside a UserControl

Posted on 2016-08-31
2
63 Views
Last Modified: 2016-09-01
In my project I am developing a UserControl that has a slider and some other controls inside it. I need to data bind to some of these controls, for example the Minimum, Maximum, and Value of the slider control. As an initial step I have created a Dependency Property on the UserControl for the "Value" property of the slider, it is called "Volume."

	Public Shared ReadOnly volumeProperty As DependencyProperty = DependencyProperty.Register("volume", GetType(Double), GetType(CA_Fader))

	Public Property volume As Double
		Get
			Return CDbl(GetValue(volumeProperty))
		End Get
		Set(value As Double)
			SetValue(volumeProperty, value)
		End Set
	End Property

Open in new window


The UserControl has this binding for the slider value property:

            <Slider x:Name="slider" Value="{Binding volume, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" Orientation="Vertical" Maximum="1" LargeChange="0.1" SmallChange="0.01" Width="30" Margin="11,4,0,3"/>

Open in new window


The user control is used on the main form of the application and I attempted to data bind the volume property like this:

                <local:CA_Fader x:Name="slider2" volume="{Binding CuePlayManager.TheMixer.MasterVolume}" Height="140" Width="74" Margin="0,2"/>

Open in new window


However, when I use the slider the "MasterVolume" property is not being updated.

Any input would be greatly appreciated,
Sid
0
Comment
Question by:Sid Price
  • 2
2 Comments
 

Accepted Solution

by:
Sid Price earned 0 total points
ID: 41780077
I have resolved this issue myself, it appears the default binding on my UserControl "volume" property was one-way. I changed the binding as shown below and it now works:

                <local:CA_Fader x:Name="slider2" volume="{Binding CuePlayManager.TheMixer.MasterVolume, Mode-TwoWay}" Height="140" Width="74" Margin="0,2"/>

Open in new window


Sid
0
 

Author Closing Comment

by:Sid Price
ID: 41780079
Resolved through own research and debugging
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Bartender Integration Builder 3 20
REXEX help Part 2 2 25
RLDC Reporting in Visual studio 11 16
backup program with robocopy 6 22
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
A short article about problems I had with the new location API and permissions in Marshmallow
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question