Situation: I set Storyboard.SetTargetProperty for BlurEffect by string.
Problem: It feels not easy, because IntelliSense doesn't work for string.
Workaround: I feel i can do it by in a complex way, but the goal is to do, for example, just like i do with Line position setting it by reference.
Questions:
1. How to set it by reference easy without complexity?
2. How can i know what property path to use?
3. How to enable IntelliSense?
Notes:
1. It must be done in C# using Storyboard, not XAML.
2. Setting by reference works fine, for example, for Line position, but the same doesn't work for BlurEffect at all.
Code:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Loaded += MainWindow_Loaded;
}
Line line;
BlurEffect blur;
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
Canvas canvas = new Canvas();
canvas.Background = Brushes.Black;
this.Content = canvas;
blur = new BlurEffect();
blur.Radius = 20;
line = new Line();
line.Stroke = Brushes.White;
line.X1 = 0;
line.Y1 = 0;
line.X2 = 100;
line.Y2 = 100;
line.Effect = blur;
canvas.Children.Add(line);
Animation();
}
private void Animation()
{
DoubleAnimation da = new DoubleAnimation();
da.To = 0;
da.Duration = TimeSpan.FromSeconds(1);
Storyboard sb = new Storyboard();
Storyboard.SetTarget(da, line);
Storyboard.SetTargetProperty(da, new PropertyPath("Effect.Radius"));
sb.Children.Add(da);
sb.Begin();
}
}
> as any dependency property that is of double format is valid for animation.
The next code doesn't work:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Loaded += MainWindow_Loaded;
}
BlurEffect blur;
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
Canvas canvas = new Canvas();
canvas.Background = Brushes.Black;
this.Content = canvas;
blur = new BlurEffect();
blur.Radius = 20;
Line line = new Line();
line.Stroke = Brushes.White;
line.X1 = 0;
line.Y1 = 0;
line.X2 = 100;
line.Y2 = 100;
line.Effect = blur;
canvas.Children.Add(line);
Animation();
}
private void Animation()
{
DoubleAnimation da = new DoubleAnimation();
da.To = 0;
da.Duration = TimeSpan.FromSeconds(0);
Storyboard sb = new Storyboard();
Storyboard.SetTarget(da, blur);
Storyboard.SetTargetProperty(da, new PropertyPath(BlurEffect.RadiusProperty));
sb.Children.Add(da);
sb.Begin();
}
}
But when i call BeginAnimation on a BlurEffect instance, it works.
Code:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Loaded += MainWindow_Loaded;
}
BlurEffect blur;
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
Canvas canvas = new Canvas();
canvas.Background = Brushes.Black;
this.Content = canvas;
blur = new BlurEffect();
blur.Radius = 20;
Line line = new Line();
line.Stroke = Brushes.White;
line.X1 = 0;
line.Y1 = 0;
line.X2 = 100;
line.Y2 = 100;
line.Effect = blur;
canvas.Children.Add(line);
Animation();
}
private void Animation()
{
DoubleAnimation da = new DoubleAnimation();
da.To = 0;
da.Duration = TimeSpan.FromSeconds(0);
blur.BeginAnimation(BlurEffect.RadiusProperty, da);
}
}