2014-03-28 2 views
2

현재 Caliburn을 구현 중이며 마우스 오버 구현이 있습니다. 어떻게 마우스 커서를 단추로 변경합니까 궁금하네요.버튼 위로 마우스 커서를 어떻게 바꿀 수 있습니까?

XAML 사이드 :

<Button cal:Message.Attach="[Event MouseOver] = [ChangeIcon]" /> 
+0

어쩌면 스타일 트리거 – RadioSpace

+0

사용 CSS 버튼 { 커서 : 포인터; } http://ux.stackexchange.com/questions/3788/default-cursor-on-mouse-over-of-a-button-is-not-a-hand-pointer 여기를 보거나

답변

8

뒤에 코드에서

<Button x:Name="btn" MouseEnter="btn_OnMouseEnter" MouseLeave="btn_OnMouseLeave" /> 

을 시도합니다. 그냥 Button이 트리거의 Style에 추가 :

<Style TargetType="{x:Type Button}"> 
    <Style.Triggers> 
     <Trigger Property="IsMouseOver" Value="True"> 
      <Setter Property="Cursor" Value="Wait" /> 
     </Trigger> 
    </Style.Triggers> 
</Style> 

게다가, 커서 및 마우스 이벤트가 View 관련이있다. 즉, ViewModel이 아닌이 작업을 수행하고 View의 측면에서 수행하는 것이 바람직 함을 의미합니다.

+1

멋진 솔루션을 사랑해! UI가 XAML에 유지되도록합니다. – aloisdg

+1

위대한 솔루션 버드! – Master

+1

내가 제안한 것보다 낫다. 매일 새로운 것을 배우십시오! 나는 이것을 나 자신으로 사용할 것이다. 건배! – ryrich

3

커서를 변경하려면, 당신은 Mouse.OverrideCursor Property

다음
private void CursorTypeChanged(object sender, SelectionChangedEventArgs e) 
{ 
    Mouse.OverrideCursor = Cursors.Wait; 
} 

재설정하는 데 사용할 수있는, 당신은 사용할 수 있습니다

Mouse.OverrideCursor = null; 

또 다른 예를 (msdn에서)

// Determines the scope the new cursor will have. 
// 
// If the RadioButton rbScopeElement is selected, then the cursor 
// will only change on the display element. 
// 
// If the Radiobutton rbScopeApplication is selected, then the cursor 
// will be changed for the entire application 
// 
private void CursorScopeSelected(object sender, RoutedEventArgs e) 
{ 
    RadioButton source = e.Source as RadioButton; 

    if (source != null) 
    { 
     if (source.Name == "rbScopeElement") 
     { 
      // Setting the element only scope flag to true 
      cursorScopeElementOnly = true; 

      // Clearing out the OverrideCursor. 
      Mouse.OverrideCursor = null; 
     } 
     if (source.Name == "rbScopeApplication") 
     { 
      // Setting the element only scope flag to false 
      cursorScopeElementOnly = false; 

      // Forcing the cursor for all elements. 
      Mouse.OverrideCursor = DisplayArea.Cursor; 
     } 
    } 
} 

추가 정보가 필요하십니까? 커서 클래스의 특성

  • 목록 : msdn
  • 좋은 "방법"msdn에 있습니다.
1

XAML에서 당신은 이것에 대한 이벤트 처리기를 만들 필요가 없습니다

private void btn_OnMouseEnter(object sender, MouseEventArgs e) 
{ 
    // example. you can change to a specific type in the Cursors static class 
    Cursor.Current = Cursors.WaitCursor; 
} 

private void btn_OnMouseLeave(object sender, MouseEventArgs e) 
{ 
    Cursor.Current = Cursors.Default; 
} 
2

다른 곳에서는 Mouse.OverrideCursor를 사용하지 마십시오. Cursor = "Hand"는 작동하지 않습니다. 앱 호출이를로드 할 때

대신 :

Mouse.OverrideCursor = null;

사방이 전화 :

<Button Cursor="Hand"/>

전체 앱 공간에 커서를 설정합니다 Mouse.OverrideCursor를 사용!

관련 문제