Solved

WPF - External data binding to controls inside a UserControl

Posted on 2016-08-31
2
42 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
Comment Utility
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
Comment Utility
Resolved through own research and debugging
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Hangfire / asp.net sample 3 27
Check if number is currency 15 27
Get String split 5 31
Closing all open child forms. 4 22
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now