当前位置:  开发笔记 > 后端 > 正文

如何在Silverlight数据网格中删除鼠标悬停突出显示和选定的行突出显示

如何解决《如何在Silverlight数据网格中删除鼠标悬停突出显示和选定的行突出显示》经验,为你挑选了1个好方法。

我有一个datagrid,每行有一个按钮(xaml如下所示).我试图摆脱突出显示所选行的蓝色突出显示功能,以及鼠标悬停在其上的行.我正在尝试将其设置为只需单击按钮而不会获得行选择和鼠标悬停突出显示功能.我尝试将IsHitTestVisible设置为false,但是按钮不可单击.我怎样才能做到这一点?

                         

    
        
            
                
                    
                
            
        
    

Scott.. 5

The short answer is to use styles. The long answer is the following:

There are two style properties in the Silverlight 2.0 datagrid that should solve your problem. The first is CellStyle and the second is RowStyle. The CellStyle property is the one which will remove the light blue highlight around the currently selected cell. The RowStyle property is the one where you will be able to remove the light blue shade indicating the selected row. The CellStyle that I used is as follows:

    

If you will notice, I commented out the storyboard that changed the FocusVisual rectangle's opacity value. What this was doing was to set the FocusVisual rectangle to be shown on cell selection. (Please Note: You cannot remove the FocusVisual Element as the CellPresenter is expecting this element, and not finding the element will cause an error.)

我使用的RowStyle如下:

    

如你所见,我评论了一些更多的视觉状态.您需要注释掉MouseOver VisualState故事板,Normal Selected故事板,MouseOver Selected故事板和Unfocused Selected故事板.

(请注意:我没有删除这些视觉状态,我只是评论了他们过去做过的事情.)

这是我的完整代码供参考:(首先是XAML,然后是VB)

XAML:




    

    



    

        
            
                
                    
                        
                    
                
            
        
    


VB:

Partial Public Class Page
Inherits UserControl

Public Sub New()
    InitializeComponent()
    Dim test As IList(Of String) = New List(Of String)
    test.Add("test1")
    test.Add("test1")
    test.Add("test1")
    test.Add("test1")
    test.Add("test1")
    test.Add("test1")
    test.Add("test1")
    test.Add("test1")
    test.Add("test1")
    test.Add("test1")

    TestGrid.ItemsSource = test

End Sub

Private Sub btnClinic_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)

End Sub
End Class

希望这可以帮助.

谢谢,斯科特



1> Scott..:

The short answer is to use styles. The long answer is the following:

There are two style properties in the Silverlight 2.0 datagrid that should solve your problem. The first is CellStyle and the second is RowStyle. The CellStyle property is the one which will remove the light blue highlight around the currently selected cell. The RowStyle property is the one where you will be able to remove the light blue shade indicating the selected row. The CellStyle that I used is as follows:

    

If you will notice, I commented out the storyboard that changed the FocusVisual rectangle's opacity value. What this was doing was to set the FocusVisual rectangle to be shown on cell selection. (Please Note: You cannot remove the FocusVisual Element as the CellPresenter is expecting this element, and not finding the element will cause an error.)

我使用的RowStyle如下:

    

如你所见,我评论了一些更多的视觉状态.您需要注释掉MouseOver VisualState故事板,Normal Selected故事板,MouseOver Selected故事板和Unfocused Selected故事板.

(请注意:我没有删除这些视觉状态,我只是评论了他们过去做过的事情.)

这是我的完整代码供参考:(首先是XAML,然后是VB)

XAML:




    

    



    

        
            
                
                    
                        
                    
                
            
        
    


VB:

Partial Public Class Page
Inherits UserControl

Public Sub New()
    InitializeComponent()
    Dim test As IList(Of String) = New List(Of String)
    test.Add("test1")
    test.Add("test1")
    test.Add("test1")
    test.Add("test1")
    test.Add("test1")
    test.Add("test1")
    test.Add("test1")
    test.Add("test1")
    test.Add("test1")
    test.Add("test1")

    TestGrid.ItemsSource = test

End Sub

Private Sub btnClinic_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)

End Sub
End Class

希望这可以帮助.

谢谢,斯科特

推荐阅读
手机用户2502852037
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有