I would like to make a textblock display the remaining time of an operation. The bound object has two properties: ElapsedTime and TotalDuration, both of type TimeSpan.
I thought the following should work, but it doesn't because the parameter passed to my custom converter is a Binding object, instead of the result of the binding:
<TextBlock
Text="{Binding ElapsedTime,
Mode=OneWay,
ConverterParameter={Binding TotalDuration},
Converter={StaticResource RemainingTimeConverter}}" />
The RemainingTimeConverter is implemented to subtract the "value" from the "parameter" and return a string representation of the resultant TimeSpan value.
Why isn't the inner Binding evaluated and its value passed to the outter binding ConverterParameter Is this by design If that's the case what's the use of having ConverterParameter if I can only use harcoded values

How can I bind a ConverterParameter value ?
brk
I was trying to somehow get that
I was able to access a property in the customcontrol like this
<
Binding Path="prop1" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type local:CustomControl1}}"></Binding>but the for another property, I need to multiply that with another property in the control
that is where I am having issues
NeoBugs
I am not very familiar with MarkupExtensions. However, I believe it may be possible to write one to replace "Binding" where we could solve this problem in a more appropriate manner.
_Andrew
how did you solve this
can you give me an example
Thanks
andrea loleo
asmo
The answer is straight-forward, but not what you want to hear.
You can only target a binding at DependencyProperty on a DependencyObject. Binding does not inherit from DO, so you can't binding the converter parameter.
If you want other state passed into a converter, you may have to subclass the desired obect and add new properties (as has been suggested).
Martin Stein
my mistake, the second one is not property on the control it is bound to a data ( a data element in the bound data)
Gerard van Soest
mancha
Then you instantiate your class with XAML, and pass it as a parameter.
create class MyTimeDuration with property for TotalDuration.
in XAML you add in resources:
<(namespace of class):MyTimeDuration x:Key="MyDuration">
Then you pass the key as the ConvertParameter like:
ConvertParameter={StaticResource MyDuration}
You can also add public functions to reset your duration such that you can bind it to a button.
Hope this helps.
Geeks
Yes, I could instantiate a helper class in XAML just to do that but that would be a workaround and not elegant. I have also found other tricks I could do but I am looking for the appropriate solution since the goal of the project I am working on is just to learn WPF.
It would be very strange to be limited to XAML hardcoded values (and resources) when setting the ConvertParameter property, don't you agree
Kalle B
Lusty_Learner
bongolas
If you want to multiply a property by another property in the same instance, why don't you create a third property that multiplies the first two and just bind to that property
DragonVic
You have to figure out a way to pass the instance of the custom control as a parameter to the converter. Then, inside, the converter access the property on that instance.
I don't know how you can pass an instance of the custom control in XAML. Maybe you can pass a StaticResource which in turn could povide the instance ...
What is strange for me is that it's easy to assign a Name to the objects we declare in XAML. However, I have never seem a way to refer to those instances by the Name in XAML. Isn't this a design oversight
Calvin Thomas
Could someone help me with this
Thanks