鼠标事件在 RadToolbar 中不起作用

Mouse Event Didn't Work In RadToolbar

我有一个 radtoolbar,里面有两个按钮,其中一个按钮有 Mouse Enter 事件,它改变了按钮的背景。但没有用,按钮不会改变

有什么问题?

工具栏组件:

<telerik:RadToolBar x:Name="radToolbar" FocusManager.IsFocusScope="False" Height="30" Margin="0" VerticalAlignment="Top">
        <Button Content="Button" Margin="0,0,0,-2" Width="75"/>
        <telerik:RadButton x:Name="mybutton" Content="Button" Height="Auto" Margin="0,0,0,-2" Width="60" MouseEnter="mybutton_MouseEnter">

        </telerik:RadButton>
    </telerik:RadToolBar>

鼠标事件:

private void mybutton_MouseEnter(object sender, MouseEventArgs e)
    {
        this.mybutton.Background = new SolidColorBrush(Color.FromArgb(100, 20, 50, 200));
    }

RadToolBar 具有许多可包含在工具栏中的常用控件的预定义样式,覆盖在 XAML 中或通过代码对样式所做的任何显式更改。

说明此行为的一个戏剧性方法是使用对代码的此更改删除所有 预定义样式:

<telerik:RadToolBar x:Name="radToolbar" FocusManager.IsFocusScope="False" Height="30" Margin="0" VerticalAlignment="Top">
    <telerik:RadToolBar.Resources>
        <Style TargetType="telerik:RadToolBar">
            <Setter Property="ItemContainerStyleSelector" Value="{x:Null}"/>
        </Style>
    </telerik:RadToolBar.Resources>
    <Button Content="Button" Margin="0,0,0,-2" Width="75"/>
    <telerik:RadButton x:Name="mybutton" Content="Button" Height="Auto" Margin="0,0,0,-2" Width="60" MouseEnter="mybutton_MouseEnter" >
     </telerik:RadButton>
</telerik:RadToolBar>

您的代码现在应该可以处理样式的其他部分可能需要您自己重新添加的副作用(相当大的工作!)。

在此 Telerik forum thread, and a link is given to a Telerik SDK demo 此处讨论了将样式应用于 RadBarTool 中的控件的各种技术。