I have a ValueConverter used to bind the "To" value in a StoryBoard animation, similar to answer - WPF animation: Bind to the "To" attribute of the storyboard animation .
The problem is that I am repeating the code snippet below for MultiBinding ValueConverter in several places.
<MultiBinding Converter="{StaticResource multiplyConverter}"> <Binding Path="ActualHeight" ElementName="ExpanderContent"/> <Binding Path="Tag" RelativeSource="{RelativeSource Self}" /> </MultiBinding>
I want to remove this duplicate code by storing the result of the ValueConverter in a resource variable so that I can bind this local variable directly to the message board.
<system:Double x:Key="CalculatedWidth"> <MultiBinding Converter="{StaticResource multiplyConverter}"> <Binding Path="ActualHeight" ElementName="ExpanderContent"/> <Binding Path="Tag" RelativeSource="{RelativeSource Self}" /> </MultiBinding> </system:Double >
I get the following error:
The "Double" type does not support direct content.
Cannot add content to a Double object.
I believe this is a common problem, but I am not able to find a solution to remove this redundancy.
Update
Thanks Rohit , your answer solved the problem. But I have one more related problem, so I am updating the question. This CalculatedWidth variable works fine in the normal case, but when it is used in RenderTransform, it does not get the value. those. if I use the usual way of using the converter, it works, but it does not pick up the variable.
<StackPanel.RenderTransform> <TranslateTransform x:Name="SliderTransform"> <TranslateTransform.X> <Binding Converter="{StaticResource PanelConverter}" ElementName="SliderPanel" Path="ActualWidth" /> // Works <Binding Path="Width" Source="{StaticResource CalculatedWidth}"/> // Doesn't Work </TranslateTransform.X> </TranslateTransform> </StackPanel.RenderTransform>
I saved the variable as part of a local resource. Does this mean that the variable is not created during the Render conversion?