XAML UWP 응용 프로그램에서 Button을 확장하는 클래스를 지정합니다. Ive가 Background ImageBrush를 설정했습니다.XAML UWP 사용자 지정 단추의 backgound 포커스
내 버튼은 포커스가 있거나 mouseover 이벤트가 발생하면 내 버튼에 검은 색 테두리가있는 회색 사각형이 나타납니다.
필자는 이벤트의 다양한 종류 (gotFocus
, mouseEntered
, mouseover
)에 수정 FocusVisualPrimary/SecondaryBrush에 전경을 변경, 많은 용액 shitton 시도. 아무 것도 작동하지 않았으므로 최상의 결과를 얻으려면 button.Background = "originalBitmapImage"
을 mouseover
이벤트 (원래 배경과 동일한 이미지 경로로 새 ImageBrush를 만든 다음 BackGround에 할당 함)에 마우스 오버가 발생하면 이미지가 모두 깜박입니다. 매번 새로운 이미지를 새로 고침). 여기
내가 난, 두 경우에 동일한 이미지를 유지하고 싶습니다 이 작업을 수행하는 방법에 대해 약간의 손실이 있습니다.
public class MyButton : Button
{
private static string Image_path = "ms-appx:///assets/Button.png";
public MyButton()
{
ImageBrush brush = new ImageBrush()
{
ImageSource = new BitmapImage(new Uri(MyButton.Image_path))
};
this.Background = brush;
this.PointerEntered += a;
}
// This almost work, but the image is flickering when event is fired
private void a(object sender, PointerRoutedEventArgs e)
{
ImageBrush brush = new ImageBrush()
{
ImageSource = new BitmapImage(new Uri(MyButton.Image_path))
};
//this.Foreground = brush;
this.Background = brush;
}
}
. 이 이상한 행동을 방지하려면 템플릿을 만들거나 ContentControl을 사용하여 콘텐츠를 이미지로 설정하거나 테두리를 배경 속성 인 – sTrenat