Bạn có các sự kiện Activated
và Deactivated
của Application
.
Nếu bạn muốn để có thể liên kết với IsActive
bạn có thể thêm một tài sản trong App.xaml.cs
<TextBlock Text="{Binding Path=IsActive,
Source={x:Static Application.Current}}"/>
tất nhiên bạn cũng có thể truy cập vào tài sản này trong mã như
App application = Application.Current as App;
bool isActive = application.IsActive;
App.xaml .cs
public partial class App : Application, INotifyPropertyChanged
{
private bool m_isActive;
public bool IsActive
{
get { return m_isActive; }
private set
{
m_isActive = value;
OnPropertyChanged("IsActive");
}
}
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Activated += (object sender, EventArgs ea) =>
{
IsActive = true;
};
Deactivated += (object sender, EventArgs ea) =>
{
IsActive = false;
};
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Nguồn
2011-08-13 11:47:38
Ghi đè phương thức OnActivate và OnDeactive của biểu mẫu. Các nút nhấp nháy không phải là cách tiếp cận giao diện người dùng lớn nhất, thay vào đó hãy xem xét một NotifyIcon. Nhưng chỉ hiển thị bóng khi đã không còn hoạt động. –