我目前正在实施Caliburn并实施鼠标悬停。我想知道如何在按钮上将鼠标光标更改为鼠标。
Xaml Side:
<Button cal:Message.Attach="[Event MouseOver] = [ChangeIcon]" />
答案 0 :(得分:10)
您无需为此创建事件处理程序。只需添加到 Style
的Button
此触发器:
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Cursor" Value="Wait" />
</Trigger>
</Style.Triggers>
</Style>
此外,Cursor和Mouse事件与View
相关。这意味着需要在ViewModel
中执行此操作,并在View
一侧执行此操作。
答案 1 :(得分: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;
}
}
}
需要更多信息?
答案 2 :(得分:2)
不要在任何地方使用Mouse.OverrideCursor,否则Cursor =“Hand”将无效。
而是在加载你的应用程序时调用它:
Mouse.OverrideCursor = null;
到处都叫这个:
<Button Cursor="Hand"/>
使用Mouse.OverrideCursor将为整个App Space设置光标!
答案 3 :(得分:1)
在xaml尝试
<Button x:Name="btn" MouseEnter="btn_OnMouseEnter" MouseLeave="btn_OnMouseLeave" />
中的代码
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;
}