Solved

WPF - External data binding to controls inside a UserControl

Posted on 2016-08-31
2
69 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

828 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