or
Imports System
Imports Microsoft.Win32
Imports Telerik.Windows
Imports Telerik.Windows.Controls
Public Class OpenFileDialogEx
Public Shared ReadOnly FilterProperty As DependencyProperty = DependencyProperty.RegisterAttached("Filter", GetType(String), GetType(OpenFileDialogEx), New PropertyMetadata("All documents (.*)|*.*", Sub(d, e) AttachFileDialog(DirectCast(d, TextBox), e)))
Public Shared Function GetFilter(element As UIElement) As String
Return DirectCast(element.GetValue(FilterProperty), String)
End Function
Public Shared Sub SetFilter(element As UIElement, value As String)
element.SetValue(FilterProperty, value)
End Sub
Private Shared Sub AttachFileDialog(textBox As TextBox, args As DependencyPropertyChangedEventArgs)
Dim parent = DirectCast(textBox.Parent, Panel)
''added this because there was a problem with double binding and it was causing the filebrowser dialog to pop up twice
Dim tag = TryCast(parent.Tag, String)
If Not IsNothing(tag) Then Return
parent.Tag = "already bound"
AddHandler parent.Loaded, Sub()
Dim button = DirectCast(parent.Children.Cast(Of Object)().FirstOrDefault(Function(x) TypeOf x Is Button), Button)
Dim filter = DirectCast(args.NewValue, String)
AddHandler button.Click, Sub(s, e)
Dim dlg = New OpenFileDialog()
dlg.Filter = filter
Dim result = dlg.ShowDialog()
If result = True Then
textBox.Text = dlg.FileName
End If
End Sub
End Sub
End Sub
End Class
Public Class DataFormImageFileBrowser
Inherits DataFormDataField
Protected Overrides Function GetControlBindingProperty() As DependencyProperty
Return TextBox.TextProperty
End Function
Protected Overrides Function GetControl() As Control
Dim fd = New OpenFileDialogUC("Image file (pdf,png,gif,jpg,bmp,tif,emf,wmf)|*.pdf;*.png;*.gif;*.jpg;*.bmp;*.jpeg;*.tiff;*.tif;*.emf;*.wmf")
Dim dependencyProperty As DependencyProperty = GetControlBindingProperty()
If Not IsNothing(DataMemberBinding) Then
Dim binding = DataMemberBinding
fd.FileNameTbx.SetBinding(dependencyProperty, binding)
End If
Return fd
End Function
End Class
<
UserControl
x:Class
=
"OpenFileDialogUC"
xmlns:src
=
"clr-namespace:CarWashInventoryManagement"
mc:Ignorable
=
"d"
>
<
Grid
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"*"
/>
<
ColumnDefinition
Width
=
"Auto"
/>
</
Grid.ColumnDefinitions
>
<
TextBox
x:Name
=
"FileNameTbx"
MinWidth
=
"100"
src:OpenFileDialogEx.Filter
=
"{Binding FilterStr}"
Grid.Column
=
"0"
/>
<
Button
Grid.Column
=
"1"
>Browse</
Button
>
</
Grid
>
</
UserControl
>
Public Class OpenFileDialogUC
Public Property FilterStr As String = String.Empty
Public Sub New(_filter As String)
FilterStr = _filter
DataContext = Me
InitializeComponent()
End Sub
End Class
ElseIf e.PropertyName = "FileName" Then
Dim df = New DataFormImageFileBrowser()
df.Label = e.DataField.Label
df.DataMemberBinding = e.DataField.DataMemberBinding
e.DataField = df
e.DataField.Label = "File Name"
<
RadSplitContainer
Dock
=
"DockedTop"
Orientation
=
"Vertical"
>
<
Items
>
<
RadPaneGroup
RelativeWidth
=
"100"
RelativeHeight
=
"100"
SplitterChange
=
"422,180833333333"
SelectedIndex
=
"0"
>
<
Items
>
<
RadPane
SerializationTag
=
"LineAppearancesPane"
IsDockable
=
"True"
/>
</
Items
>
</
RadPaneGroup
>
<
RadPaneGroup
RelativeWidth
=
"100"
RelativeHeight
=
"300"
SplitterChange
=
"554,5425"
SelectedIndex
=
"0"
>
<
Items
>
<
RadPane
SerializationTag
=
"CallControlWheelPane"
IsDockable
=
"True"
Header
=
""
CanFloat
=
"False"
/>
</
Items
>
</
RadPaneGroup
>
</
Items
>
</
RadSplitContainer
>
<
Application
x:Class
=
"Green.App"
xmlns:local
=
"clr-namespace:Green"
>
<
Application.Resources
>
<
ResourceDictionary
>
<
ResourceDictionary.MergedDictionaries
>
<
ResourceDictionary
>
<
local:AppBootstrapper
x:Key
=
"bootstrapper"
/>
</
ResourceDictionary
>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Windows8;component/Themes/System.Windows.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.Input.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.Navigation.xaml"
/>
</
ResourceDictionary.MergedDictionaries
>
</
ResourceDictionary
>
</
Application.Resources
>
</
Application
>
var cellImage = new Image() { Width = 20, Height = 20 };
var imageUri = "../AppResources/Images/flag.png";
cellImage.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(imageUri, UriKind.Relative));
this.jobsGridView.CurrentCell.ParentRow.Cells[2].Content = cellImage;
<Style x:Key=
"DraggableListBoxItem"
TargetType=
"telerik:RadListBoxItem"
>
<Setter Property=
"telerik:DragDropManager.AllowCapturedDrag"
Value=
"True"
/>
<Setter Property=
"telerik:DragDropManager.AllowDrag"
Value=
"True"
/>
<Setter Property=
"telerik:DragDropManager.TouchDragTrigger"
Value=
"TapAndHold"
/>
</Style>
<DataTemplate x:Key=
"ListBoxItemTemplate"
>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=
"Auto"
/>
<ColumnDefinition Width=
"Auto"
/>
</Grid.ColumnDefinitions>
<Image Source=
"/Dashboard_UserExtension;component/Images/usericon.png"
Margin=
"10 0 0 0"
Width=
"16"
Height=
"16"
Grid.Column=
"0"
HorizontalAlignment=
"Left"
/>
<TextBlock Text=
"{Binding Username}"
FontSize=
"12"
FontFamily=
"Segoe UI"
Grid.Column=
"1"
Margin=
"10 0 0 0"
HorizontalAlignment=
"Left"
/>
</Grid>
</DataTemplate>
<telerik:RadListBox
x:Name=
"AdminUserBox"
AllowDrop=
"True"
ItemTemplate=
"{StaticResource ListBoxItemTemplate}"
ItemContainerStyle=
"{StaticResource DraggableListBoxItem}"
HorizontalAlignment=
"Left"
Margin=
"0,10,0,1"
Width=
"150"
ItemsSource=
"{Binding AdminUserList}"
Drop=
"AdminUserBox_Drop"
>
<telerik:RadListBox.DragVisualProvider>
<telerik:ScreenshotDragVisualProvider />
</telerik:RadListBox.DragVisualProvider>
<telerik:RadListBox.DragDropBehavior>
<telerik:ListBoxDragDropBehavior AllowReorder=
"True"
/>
</telerik:RadListBox.DragDropBehavior>
</telerik:RadListBox>
<telerik:RadTreeView x:Name=
"UserTreeView"
HorizontalAlignment=
"Left"
Margin=
"0,10,-2,0"
Width=
"220"
IsDragDropEnabled=
"True"
ItemTemplate=
"{StaticResource UserTemplate}"
ItemsSource=
"{Binding UserList}"
IsLoadOnDemandEnabled=
"False"
IsSingleExpandPath=
"True"
ItemContainerStyle=
"{StaticResource UsersItemContainerStyle}"
AllowDrop=
"False"
>
</telerik:RadTreeView>
private
void
AdminUserBox_Drop(
object
sender, System.Windows.DragEventArgs e)
{
MessageBox.Show(
"Drop!"
);
// Not shown when dropping to AdminUserBox
}
- Group 1
XXXXXXXXXXXX O O O O O O O O O
XXXXXXXXXXXX XXXXXXXXXXXX
+ Group 2
- Group 1
XXXXXXXXXXXX O O O
XXXXXXXXXXXX O O O
XXXXXXXXXXXX O O O
+ Group 2