About the WPF Globe Gallery Sample
[C#]
mapClasses.cs
using System; using System.Collections.ObjectModel; using System.IO; using System.Windows.Media.Imaging; namespace GlobeGallery { /// <summary> /// This class describes a single map - its location, the map name /// </summary> public class Map { public Map (string path) { _path = path; _source = new Uri (path); _image = BitmapFrame.Create (_source); string sub = path.Substring (path.LastIndexOf ("\\") + 1); _mapName = sub.Substring(0,sub.Length-4); } private string _path; private string _mapName; public string MapName { get { return _mapName; } } private Uri _source; public string Source { get { return _path; } } private BitmapFrame _image; public BitmapFrame Image { get { return _image; } set { _image = value; } } } /// <summary> /// This class represents a collection of map images in a directory. /// </summary> public class MapCollection: ObservableCollection<Map> { public MapCollection () { } public MapCollection (string path) : this (new DirectoryInfo (path)) { } public MapCollection (DirectoryInfo directory) { _directory = directory; Update (); } public string Path { set { _directory = new DirectoryInfo (value); Update (); } get { return _directory.FullName; } } public DirectoryInfo Directory { set { _directory = value; Update (); } get { return _directory; } } private void Update () { this.Clear (); try { foreach (FileInfo f in _directory.GetFiles ("*.jpg")) Add (new Map (f.FullName)); } catch (DirectoryNotFoundException) { System.Windows.MessageBox.Show ("No Such Directory"); } } DirectoryInfo _directory; } /// <summary> /// This class returns a local data path as global variable. /// </summary> public class data { public static string GetLocalDataPath () { string rootPath = Environment.CurrentDirectory; int position = rootPath.LastIndexOf ("\\"); string subString = rootPath.Substring (0, position); return rootPath.Substring(0,subString.LastIndexOf("\\")); } } }
[Visual Basic .NET]
mapClasses.vb
Imports Microsoft.VisualBasic Imports System Imports System.Collections.ObjectModel Imports System.IO ''' <summary> ''' This class describes a single map - its location, the map name ''' </summary> Public Class Map Public Sub New(ByVal path As String) _path = path _source = New Uri(path) _image = BitmapFrame.Create(_source) Dim [sub] As String = path.Substring(path.LastIndexOf("\") + 1) _mapName = [sub].Substring(0, [sub].Length - 4) End Sub Private _path As String Private _mapName As String Private _source As Uri Private _image As BitmapFrame Public ReadOnly Property MapName() As String Get Return _mapName End Get End Property Public ReadOnly Property Source() As String Get Return _path End Get End Property Public Property Image() As BitmapFrame Get Return _image End Get Set(ByVal value As BitmapFrame) _image = Value End Set End Property End Class ''' <summary> ''' This class represents a collection of map images in a directory. ''' </summary> Public Class MapCollection : Inherits ObservableCollection(Of Map) Public Sub New() End Sub Private _directory As DirectoryInfo Public Sub New(ByVal mapPath As String) Me.New(New DirectoryInfo(mapPath)) End Sub Public Sub New(ByVal directory As DirectoryInfo) _directory = directory Update() End Sub Public Property Path() As String Set _directory = New DirectoryInfo (Value) Update () End Set Get Return _directory.FullName End Get End Property Public Property Directory() As DirectoryInfo Set _directory = Value Update () End Set Get Return _directory End Get End Property Private Sub Update() Me.Clear () Try For Each f As FileInfo In _directory.GetFiles ("*.jpg") Add (New Map (f.FullName)) Next f Catch e1 As DirectoryNotFoundException System.Windows.MessageBox.Show ("No Such Directory") End Try End Sub End Class ''' <summary> ''' This class returns a local data path as global variable. ''' </summary> Public Class data Public Shared Function GetLocalDataPath() As String Dim rootPath As String = Environment.CurrentDirectory Dim position As Integer = rootPath.LastIndexOf ("\") Dim subString As String = rootPath.Substring (0, position) Return rootPath.Substring(0,subString.LastIndexOf("\")) End Function End Class