public void ChangeIcon(CautionState state) { Uri imageUri; switch (state) { case CautionState.Informational: imageUri = new Uri("pack://application:,,,/WindowsInfo.png", UriKind.RelativeOrAbsolute); break; case CautionState.Fleeing: imageUri = new Uri("pack://application:,,,/WindowsWarning.png", UriKind.RelativeOrAbsolute); break; case CautionState.Panicing: imageUri = new Uri("pack://application:,,,/WindowsError.png", UriKind.RelativeOrAbsolute); break; default: imageUri = new Uri("pack://application:,,,/WindowsInfo.png", UriKind.RelativeOrAbsolute); break; } PngBitmapDecoder decoder = new PngBitmapDecoder(imageUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); BitmapSource bitmapSource = decoder.Frames[0]; m_Icon.Source = bitmapSource; }
// Determines which state to be in based on the distance from the cursor to the window private void DetermineState() { CautionState oldState = state; double dst = window.GetDistance(); if (dst < PanicDst) { state = CautionState.Panicing; } else if (dst < FleeDst) { state = CautionState.Fleeing; } else { state = CautionState.Informational; } if (oldState != state) { StateChanged(); } }