私はブラシを2本持っています。ブラシの種類がわかりません。それらは、ImageBrushes、SolidBrushes、または VisualBrushes にすることができます。「ブラシ」タイプの変数にそれぞれがあります。
2 つのブラシを組み合わせる必要があります。どうすればいいのですか?
これを試しました。しかし、うまくいきませんでした。これが、私が組み合わせる必要があるブラシの背面と前面です。
Border Bd = new Border();
Border Bdr = new Border();
Bd.Width = 1.0;
Bd.Height = 1.0;
Bd.Background = Back;
Bdr.Background = Front;
Bd.Child = Bdr;
Brush VB = new VisualBrush(Bd);
ブラシをアニメーション化するカスタム アニメーション クラスを作成しているため、これが必要です。いくつかのテストを行った後、エラーはブラシの組み合わせにあり、クラスの他の場所にはないと結論付けました。
結果のブラシは完全に透明になります。
[編集]
完全な BrushAnimation クラスは次のとおりです。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media.Animation;
using System.Windows;
using System.Windows.Media;
using System.Windows.Controls;
namespace WPFSoPaTest
{
class BrushAnimation : AnimationTimeline
{
protected override Freezable CreateInstanceCore()
{
return new BrushAnimation();
}
public override Type TargetPropertyType
{
get { return typeof(Brush); }
}
static BrushAnimation()
{
FromProperty = DependencyProperty.Register("From", typeof(Brush),
typeof(BrushAnimation));
ToProperty = DependencyProperty.Register("To", typeof(Brush),
typeof(BrushAnimation));
}
public static readonly DependencyProperty FromProperty;
public Brush From
{
get
{
return (Brush)GetValue(BrushAnimation.FromProperty);
}
set
{
SetValue(BrushAnimation.FromProperty, value);
}
}
public static readonly DependencyProperty ToProperty;
public Brush To
{
get
{
return (Brush)GetValue(BrushAnimation.ToProperty);
}
set
{
SetValue(BrushAnimation.ToProperty, value);
}
}
public override object GetCurrentValue(object defaultOriginValue,
object defaultDestinationValue, AnimationClock animationClock)
{
Brush fromVal = ((Brush)GetValue(BrushAnimation.FromProperty)).CloneCurrentValue();
Brush toVal = ((Brush)GetValue(BrushAnimation.ToProperty)).CloneCurrentValue();
if ((double)animationClock.CurrentProgress == 0.0)
return fromVal; //Here it workes fine.
if ((double)animationClock.CurrentProgress == 1.0)
return toVal; //It workes also here fine.
toVal.Opacity = (double)animationClock.CurrentProgress;
Border Bd = new Border();
Border Bdr = new Border();
Bd.Width = 1.0;
Bd.Height = 1.0;
Bd.Background = fromVal;
Bdr.Background = toVal;
Bd.Visibility = Visibility.Visible;
Bdr.Visibility = Visibility.Visible;
Bd.Child = Bdr;
Brush VB = new VisualBrush(Bd);
return VB; //But here it return's a transparent brush.
//If I return the 'toVal' variable here it animates correctly the opacity.
}
}
}