Hey all I am trying to fade in a background image on the main window.
Currently this is my code:
10 Dim storyboard__1 As New Storyboard()
20 Dim duration As New TimeSpan(0, 0, 1)
30 Dim animation As New DoubleAnimation()
50 animation.From = 0.0
60 animation.[To] = 1.0
70 animation.Duration = New Duration(duration)
90 Storyboard.SetTargetName(animation, "C:\Users\someone\Downloads\cabd.jpg")
100 Storyboard.SetTargetProperty(animation, New PropertyPath(Control.OpacityProperty))
Error BC30518 Overload resolution failed because no accessible 'Begin' can be called with these arguments:
'Public Overloads Sub Begin(containingObject As FrameworkElement)': Value of type 'Brush' cannot be converted to 'FrameworkElement'.
'Public Overloads Sub Begin(containingObject As FrameworkContentElement)': Value of type 'Brush' cannot be converted to 'FrameworkContentElement'. scrollView
You don't need to use a Storyboard. Just call
BeginAnimation on the target
Background.BeginAnimation(Brush.OpacityProperty, animation); // C#
As a note,
Storyboard.SetTargetName uses the
Name of an element (usually defined in XAML). Setting a file path like
"C:\Users\someone\Downloads\cabd.jpg" is pointless.
EDIT: You should of course assign a mutable Brush instance to the
Background property before trying to animate it, e.g. an
var bgBrush = new ImageBrush(new BitmapImage(new Uri(@"C:\Users\someone\Downloads\cabd.jpg"))); bgBrush.BeginAnimation(Brush.OpacityProperty, animation); Background = bgBrush;