Mini Kabibi Habibi
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows.Data
Imports DevExpress.Xpf.Grid
Imports System.Windows
Imports DevExpress.Xpf.Editors
Imports DevExpress.Data.Filtering
Imports System.Collections.ObjectModel
Imports System.Reflection
Imports System.Windows.Media
Imports System.Windows.Markup
Namespace GridDemo
Public Class MultiSelectModeConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
Return If(CType(value, MultiSelectMode) = MultiSelectMode.None, False, True)
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Return If(CBool(value), MultiSelectMode.Row, MultiSelectMode.None)
End Function
End Class
Public Class FocusedToColorConverter
Inherits MarkupExtension
Implements IValueConverter
Public Sub New()
End Sub
Public Overrides Function ProvideValue(ByVal serviceProvider As IServiceProvider) As Object
Return Me
End Function
#Region "IValueConverter Members"
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
If (CStr(parameter)) = System.Enum.GetName(GetType(FocusedGrid), CType(value, FocusedGrid)) Then
Return New SolidColorBrush(Color.FromArgb(50, 200, 0, 0))
End If
Return New SolidColorBrush(Color.FromArgb(0, 0, 0, 0))
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
#End Region
End Class
Public Class PastUnderFocusedRowToSelectedIndexConverter
Inherits MarkupExtension
Implements IValueConverter
Public Sub New()
End Sub
Public Overrides Function ProvideValue(ByVal serviceProvider As IServiceProvider) As Object
Return Me
End Function
#Region "IValueConverter Members"
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
Return If((CBool(value)), 0, 1)
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Return If((CInt(Fix(value)) = 0), True, False)
End Function
#End Region
End Class
Public Class GeneratingDataToWaitIndicatorTypeConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
Return If(CBool(value), WaitIndicatorType.None, WaitIndicatorType.Panel)
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotSupportedException("This method shouldn't be called")
End Function
End Class
Public Class IssueStatusImageConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
If value Is Nothing Then
Return Nothing
End If
Dim name As String = (CStr(value)).Replace(" ", "")
Dim path As String = "GridDemo.Images.IssueIcons." & name & ".png"
Return DevExpress.Xpf.Core.Native.ImageHelper.CreateImageFromEmbeddedResource(System.Reflection.Assembly.GetExecutingAssembly(), path)
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class
Public Class IdToUriConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
If value IsNot Nothing Then
Return "http://devexpress.com/Support/Center/p/" & value.ToString() & ".aspx"
End If
Return Nothing
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotSupportedException()
End Function
End Class
Public Class CategoryDataToImageSourceConverter
Inherits BytesToImageSourceConverter
Private Shared cachedImages As New Dictionary(Of String, Object)()
Public Overrides Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object
Dim categoryData As CategoryData = TryCast(value, CategoryData)
If value Is Nothing Then
Return Nothing
End If
If cachedImages.ContainsKey(categoryData.Name) Then
Return cachedImages(categoryData.Name)
Else
Dim image As Object = MyBase.Convert(categoryData.Picture, targetType, parameter, culture)
cachedImages.Add(categoryData.Name, image)
Return image
End If
End Function
End Class
Public Class BooleanToDefaultBooleanConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
Return If(CBool(value), DevExpress.Utils.DefaultBoolean.True, DevExpress.Utils.DefaultBoolean.False)
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class
Public Class NavigationStyleToTextConverter
Implements IValueConverter
#Region "IValueConverter Members"
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
If value Is Nothing Then
Return value
End If
If CType(value, GridViewNavigationStyle) = GridViewNavigationStyle.Cell Then
Return "By Cell"
End If
If CType(value, GridViewNavigationStyle) = GridViewNavigationStyle.Row Then
Return "By Row"
End If
Return value
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
#End Region
End Class
Public Class ScrollingAnimationDurationToBooleanConverter
Implements IValueConverter
#Region "IValueConverter Members"
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
Return System.Convert.ToDouble(value) > 0
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Return If(System.Convert.ToBoolean(value), 350, 0)
End Function
#End Region
End Class
Public Class ShowSearchPanelModeToTextConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
Dim showSearchPanelModeq? As ShowSearchPanelMode = CType(value, ShowSearchPanelMode?)
If Not showSearchPanelModeq.HasValue Then
Return value
End If
Dim showSearchPanelMode As ShowSearchPanelMode = showSearchPanelModeq.Value
Select Case showSearchPanelMode
Case ShowSearchPanelMode.Default
Return "Default"
Case ShowSearchPanelMode.Always
Return "Always"
Case ShowSearchPanelMode.Never
Return "Never"
End Select
Return value
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class
Public Class FindModeToTextConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
Dim findModeq? As FindMode = CType(value, FindMode?)
If Not findModeq.HasValue Then
Return value
End If
Dim findMode As FindMode = findModeq.Value
Select Case findMode
Case FindMode.Always
Return "Always"
Case FindMode.FindClick
Return "Find on Click"
End Select
Return value
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class
Public Class FilterConditionConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
Dim filterConditionq? As FilterCondition = CType(value, FilterCondition?)
If Not filterConditionq.HasValue Then
Return value
End If
Dim filterCondition As FilterCondition = filterConditionq.Value
Select Case filterCondition
Case FilterCondition.Default
Return "Default"
Case FilterCondition.Contains
Return "Contains"
Case FilterCondition.StartsWith
Return "Starts With"
Case FilterCondition.Like
Return "Like"
End Select
Return value
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class
Public Class SearchPanelModeConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
Return value
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Return (CType(value, ListBoxEditItem)).Content
End Function
End Class
Public Class GroupNameToImageConverter
Implements IValueConverter
Public Shared images As New List(Of String) (New String() {"administration", "inventory", "manufacturing", "quality", "research", "sales"})
Public Shared Function GetImagePathByGroupName(ByVal groupName As String) As String
groupName = groupName.ToLower()
For Each item As String In images
If groupName.Contains(item) Then
Return "/GridDemo;component/Images/MultiView/GroupName/" & item & ".png"
End If
Next item
Return groupName
End Function
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
If value Is Nothing Then
Return Nothing
End If
Return GetImagePathByGroupName(CStr(value))
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class
Public Class HeaderToImageConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
If value Is Nothing Then
Return Nothing
End If
Return "/GridDemo;component/Images/MultiView/" & (CStr(value)).Replace(" ", String.Empty) & ".png"
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class
Public Class ColumnHeaderTextConverter
Implements IValueConverter
Private privateColumnName As String
Public Property ColumnName() As String
Get
Return privateColumnName
End Get
Set(ByVal value As String)
privateColumnName = value
End Set
End Property
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
If value Is Nothing Then
Return Nothing
End If
Return If((CStr(value)) = ColumnName, "Bold", "Normal")
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class
Public Class BirthdayImageVisibilityConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
If value Is Nothing OrElse Not(TypeOf value Is DateTime) Then
Return Visibility.Collapsed
End If
Dim birthDate As DateTime = CDate(value)
Dim someDate As DateTime = DateTime.Now.AddMonths(3)
Dim someMonth As Integer = If(someDate.Month < 3, someDate.Month + 12, someDate.Month)
Dim birthMonth As Integer = If(birthDate.Month < 3, birthDate.Month + 12, birthDate.Month)
Return If((birthMonth >= DateTime.Now.Month AndAlso birthMonth <= someMonth AndAlso (If(birthDate.Month = DateTime.Now.Month, birthDate.Day > DateTime.Now.Day, True))), Visibility.Visible, Visibility.Collapsed)
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class
Public Class ViewToBooleanConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
If value Is Nothing Then
Return Nothing
End If
Return TypeOf value Is TableView OrElse TypeOf value Is TreeListView
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class
Public Class CountToVisibilityConverter
Implements IValueConverter
Private privateInvert As Boolean
Public Property Invert() As Boolean
Get
Return privateInvert
End Get
Set(ByVal value As Boolean)
privateInvert = value
End Set
End Property
#Region "IValueConverter Members"
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
Return If((CInt(Fix(value)) > 0) Xor Invert, Visibility.Visible, Visibility.Collapsed)
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
#End Region
End Class
Public Class IntToDoubleConverter
Implements IValueConverter
#Region "IValueConverter Members"
Private Function IValueConverter_Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
Return Convert.ToDouble(value)
End Function
Private Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Return Convert.ToInt32(value)
End Function
#End Region
End Class
Public Class RoundValueConverter
Inherits MarkupExtension
Implements IValueConverter
#Region "IValueConverter Members"
Private Function IValueConverter_Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
Return Math.Round(Convert.ToDouble(value))
End Function
Private Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Return Math.Round(Convert.ToDouble(value))
End Function
#End Region
Public Overrides Function ProvideValue(ByVal serviceProvider As IServiceProvider) As Object
Return Me
End Function
End Class
End Namespace