我需要有人告诉我我的错误...我读了很多文章,但无法理解事件未被解雇的原因。
我的页面:
<Grid >
<ProgressBar IsIndeterminate="True" Visibility="Collapsed"/>
<c:customcontrol SavingStarted="ShowProgressBar" />
</Grid>
代码:
private void ShowProgressBar(object sender, EventArgs e)
{
MyProgressBar.Visibility = Visibility.Visible;
}
我的控制:
public delegate void OnSavingStartedEventHandler(object sender, EventArgs e);
public partial class customcontrol : UserControl
{
public event EventHandler SavingStarted;
public virtual void OnSavingStarted (EventArgs e){
if (SavingStarted != null) {
SavingStarted(this, e);
}
}
private async void SaveMenuFlyoutItem_Click(object sender, RoutedEventArgs e)
{
OnSavingStarted(EventArgs.Empty);
//Saves the file
//will make another event to hide the progressbar
}
public ImageWithProgressRing()
{
this.InitializeComponent();
(this.Content as FrameworkElement).DataContext = this;
}
}
基本上我打算做的是当CustomControl SaveMenuFlyout_Click发生时,它需要在主页面中显示一个进度条...我还打算在保存发生后隐藏栏后进行自定义事件
出了什么问题,这是解决问题的最佳方法吗?