Я хочу сделать окно, чтобы скользить из нижней части экрана при его открытии. Однако им возникло проблемы с моим кодом, им получают следующее сообщение об ошибке при добавлении моего метода к нагруженному событиюДобавление загруженного обработчика событий
Ошибка:
Additional information: Value cannot be null.
Это код, который добавляет метод к EventHandler, и метод :
//Position the Notification
var workingArea = SystemParameters.WorkArea;
this.Left = (workingArea.Width - this.ActualWidth)/2;
//Create storyboard for animation
Loaded += animate;
}
}
}
public RoutedEventHandler animate(object sender, RoutedEventArgs e)
{
var workingArea = SystemParameters.WorkArea;
Storyboard sb = new Storyboard();
var slide = new DoubleAnimation()
{
BeginTime = TimeSpan.FromSeconds(2),
Duration = TimeSpan.FromSeconds(1),
By = -100
};
Storyboard.SetTarget(slide,this);
Storyboard.SetTargetName(this, "MyWindow");
Storyboard.SetTargetProperty(slide,new PropertyPath("(Window.Top)"));
this.Top = workingArea.Height - this.ActualHeight;
return null;
}
Edit: Это все окна Code Behind, который должен обрабатывать анимации и позиционирование.
/// <summary>
/// Interaction logic for NotificationAll.xaml
/// </summary>
public partial class NotificationAll : Window
{
public NotificationAll() : base()
{
InitializeComponent();
}
public new void Show()
{
//Ensure new notifications are placed above older ones
if (!Application.Current.Windows.Cast<Window>().Where(x =>
x != this).Any(x => x.GetType().Name == "NotificationAll"))
{
this.Topmost = true;
base.Show();
this.Owner = System.Windows.Application.Current.MainWindow;
//Position the Notification
var workingArea = SystemParameters.WorkArea;
this.Left = (workingArea.Width - this.ActualWidth)/2;
//Create storyboard for animation
Loaded += SlideFromBottom;
}
}
public void SlideFromBottom(object sender, RoutedEventArgs e)
{
MessageBox.Show("h");
var workingArea = SystemParameters.WorkArea;
Storyboard sb = new Storyboard();
var slide = new DoubleAnimation()
{
BeginTime = TimeSpan.FromSeconds(2),
Duration = TimeSpan.FromSeconds(1),
By = -100
};
Storyboard.SetTarget(slide,this);
Storyboard.SetTargetName(this, "MyWindow");
Storyboard.SetTargetProperty(slide,new PropertyPath("(Window.Top)"));
this.Top = workingArea.Height - this.ActualHeight;
}
/// <summary>
/// Close window once animation is complete
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DoubleAnimationCompleted(object sender, EventArgs e)
{
if (!this.IsMouseOver)
{
this.Close();
}
}
}
Отладчик должен указывать его на линию. Что это за линия? –
@EmpereurAiman Обновлено сообщение с тех пор, получил другую ошибку –