Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

WPF - External data binding to controls inside a UserControl

Posted on 2016-08-31
2
Medium Priority
?
181 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
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…
Progress

926 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