Mini Kabibi Habibi

Current Path : C:/Users/Public/Documents/DXperience 13.1 Demos/Silverlight/VB/GridDemo/Modules/
Upload File :
Current File : C:/Users/Public/Documents/DXperience 13.1 Demos/Silverlight/VB/GridDemo/Modules/HitTest.xaml.vb

Imports Microsoft.VisualBasic
Imports System
Imports System.Windows
Imports DevExpress.Xpf.Grid
Imports System.Collections.ObjectModel
Imports DevExpress.Xpf.Core
Imports System.Globalization
Imports System.Linq
Imports DevExpress.Xpf.Core.WPFCompatibility
Imports DevExpress.Data.Browsing
Imports DevExpress.Xpf.DemoBase
Imports DevExpress.Xpf.DemoBase.NWind
Imports System.Collections.Generic

Namespace GridDemo
	<CodeFile("Controls/ControlStyles/NameTextControl(.SL).xaml"), CodeFile("ModuleResources/HitTestTemplates(.SL).xaml"), CodeFile("ModuleResources/HitTestClasses.(cs)")> _
	Partial Public Class HitTest
		Inherits GridDemoModule
		Private ReadOnly Property TableView() As DevExpress.Xpf.Grid.TableView
			Get
				Return CType(grid.View, DevExpress.Xpf.Grid.TableView)
			End Get
		End Property
		Private hitInfoList As New ObservableCollection(Of HitTestInfo)()
		Private startPosition As Point


		Public Property AllowShowHitInfo() As Boolean
			Get
				Return CBool(GetValue(AllowShowHitInfoProperty))
			End Get
			Set(ByVal value As Boolean)
				SetValue(AllowShowHitInfoProperty, value)
			End Set
		End Property
		Public Overrides ReadOnly Property AllowRtl() As Boolean
			Get
				Return False
			End Get
		End Property

		Public Shared ReadOnly AllowShowHitInfoProperty As DependencyProperty = DependencyProperty.Register("AllowShowHitInfo", GetType(Boolean), GetType(HitTest), New UIPropertyMetadata(True))


		Public Sub New()
			InitializeComponent()

			AddHandler grid.Loaded, AddressOf grid_Loaded
			AddHandler grid.MouseEnter, AddressOf grid_MouseEnterMouseLeave
			AddHandler grid.MouseLeave, AddressOf grid_MouseEnterMouseLeave
			Dim isCheckedListener As New DependencyPropertyChangeListener("IsChecked", showHitInfoCheckEdit, AddressOf DependencyPropertyChangeHandler)
			Dim allowShowHitInfoListener As New DependencyPropertyChangeListener("AllowShowHitInfo", Me, AddressOf DependencyPropertyChangeHandler)


			hitIfoItemsControl.ItemsSource = hitInfoList

		End Sub
		Private Sub grid_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
			SetPopupIsOpen()
		End Sub
		Private Sub grid_MouseEnterMouseLeave(ByVal sender As Object, ByVal e As System.Windows.Input.MouseEventArgs)
			SetPopupIsOpen()
		End Sub
		Private Sub DependencyPropertyChangeHandler(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
			SetPopupIsOpen()
		End Sub
		Private Sub viewsListBox_SelectionChanged(ByVal sender As Object, ByVal e As DevExpress.Xpf.Editors.EditValueChangedEventArgs)
		End Sub

		Private Sub grid_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Input.MouseEventArgs)
			Dim location As Point = e.GetPosition(grid)
			Dim gridRect As Rect = DevExpress.Xpf.Core.Native.LayoutHelper.GetRelativeElementRect(grid, Application.Current.RootVisual)
			PointHelper.Offset(location, gridRect.X, gridRect.Y)
			Dim hOffset As Double = location.X - startPosition.X
			If FlowDirection = System.Windows.FlowDirection.RightToLeft Then
				hOffset = -hOffset
			End If

			hitInfoPopup.HorizontalOffset = hOffset
			hitInfoPopup.VerticalOffset = location.Y - startPosition.Y

			Dim info As GridViewHitInfoBase = GetHitInfo(e)

			hitInfoList.Clear()

			AddHitInfo("HitTest", TypeDescriptor.GetProperties(info)("HitTest").GetValue(info).ToString())

			AddHitInfo("Column",If(info.Column IsNot Nothing, TryCast(info.Column.HeaderCaption, String), "No column"))
			AddHitInfo("RowHandle", GetRowHandleDescription(info.RowHandle))
			AddHitInfo("CellValue",If(info.Column IsNot Nothing, grid.GetCellDisplayText(info.RowHandle, info.Column), Nothing))
			info.Accept(CreateDemoHitTestVisitor())
		End Sub
		Private Function CreateDemoHitTestVisitor() As GridViewHitTestVisitorBase
			Return New DemoTableViewHitTestVisitor(Me)
		End Function
		Private Function GetHitInfo(ByVal e As RoutedEventArgs) As GridViewHitInfoBase
			If TypeOf grid.View Is DevExpress.Xpf.Grid.TableView Then
				Return CType(TableView.CalcHitInfo(TryCast(e.OriginalSource, DependencyObject)), GridViewHitInfoBase)
			End If
			Return Nothing

		End Function
		Private Function GetRowHandleDescription(ByVal rowHanle As Integer) As String
			If rowHanle = GridControl.InvalidRowHandle Then
				Return "No row"
			End If
			If rowHanle = GridControl.NewItemRowHandle Then
				Return "New Item Row"
			End If
			If rowHanle = GridControl.AutoFilterRowHandle Then
				Return "Auto Filter Row"
			End If
			Return String.Format("{0} ({1})", rowHanle,If(grid.IsGroupRowHandle(rowHanle), "group row", "data row"))
		End Function
		Friend Sub AddHitInfo(ByVal name As String, ByVal text As String)
			hitInfoList.Add(New HitTestInfo(name, text))
		End Sub
		Friend Sub RemoveHitInfo(ByVal name As String)
			Dim infoToRemove As HitTestInfo = hitInfoList.Where(Function(info) info.Name = name).FirstOrDefault()
			If infoToRemove IsNot Nothing Then
				hitInfoList.Remove(infoToRemove)
			End If
		End Sub
		Friend Sub AddTotalSummaryInfo(ByVal column As ColumnBase)
			AddHitInfo("TotalSummary", column.TotalSummaryText)
		End Sub
		Friend Sub AddFixedTotalSummaryInfo(ByVal summaryData As GridTotalSummaryData)
			RemoveHitInfo("CellValue")
			AddHitInfo("FixedTotalSummary", summaryData.Item.GetFooterDisplayText(CultureInfo.CurrentCulture, summaryData.Column.FieldName, summaryData.Value, ""))
		End Sub
		Friend Sub AddGroupValueInfo(ByVal columnData As GridColumnData)
			AddHitInfo("GroupValue", String.Format("{0}: {1}", columnData.Column.FieldName, columnData.Value))
		End Sub
		Friend Sub AddGroupSummaryInfo(ByVal summaryData As GridGroupSummaryData)
			AddHitInfo("GroupSummary", summaryData.Text)
		End Sub
		Private Sub hitInfoPopup_Opened(ByVal sender As Object, ByVal e As EventArgs)
			startPosition = New Point(-10, -10)
		End Sub

		Private Sub SetPopupIsOpen()
			hitInfoPopup.IsOpen = grid.IsMouseOver AndAlso showHitInfoCheckEdit.IsChecked.Value AndAlso AllowShowHitInfo
		End Sub
	End Class
End Namespace