Application = ValueTextBoxApp IDEVersion = 1.11 GalleryName = GalleryPage = GalleryDefaultName = Target = 1 Platform = AnyCPU Language = XSharp Runtime = CLR4 Dialect = Core Folder = %ProjectPath%\Applications\ValueTextBoxApp\ PrgSubFolder = \Prg ResourcesSubFolder = \Resources Description = A sample of a TextBox control with a value property like VO. Provided by Wolfgang Riedmann NameSpace = Assembly = ValueTextBoxApp Extension = ApplicationIcon = OutputFolder = Frameworks = 1 GUID = E4B25692-2C16-4E9E-A7F7-350EF3A54C7D IncludeInProjectBuild = 1 IncludeInProjectSearch = 1 IncludeInProjectExport = 1 IncludePath = SignAssembly = 0 KeyFile = [ExportOptions] ExportResources = 1 ExportImages = 1 [ValueTextBoxApp FileGroups] FileFolder = MVVM_Base FileGroupGUID = 13FEEC60-CFF2-48E2-99BA-A78C14FEDFC1 [ValueTextBoxApp Files] File = %AppPath%\Prg\Start.prg FileGUID = 11757B25-6182-49B3-ABC3-DC780295048B FileType = Code File = %AppPath%\Prg\App.prg FileGUID = 03CA0BDA-9DDD-4933-97A3-D85C4B39CF9E FileType = Code File = %AppPath%\Prg\MVVM_Base\BindableBase.prg FileGUID = 5EDD6118-218D-4104-A17D-DF1916E39E5C FileFileGroup = 13FEEC60-CFF2-48E2-99BA-A78C14FEDFC1 FileType = Code File = %AppPath%\Prg\MVVM_Base\RelayCommand.prg FileGUID = 8FA77A6F-CED1-4F56-9B0E-74896110479D FileFileGroup = 13FEEC60-CFF2-48E2-99BA-A78C14FEDFC1 FileType = Code File = %AppPath%\Prg\Model1.prg FileGUID = 0A982206-380F-462F-81CF-5AEA4B66CD10 FileType = Code File = %AppPath%\Prg\View1.prg FileGUID = 108B7B2A-F63A-4892-9EDE-8B5C2479842F FileType = Code File = %AppPath%\Prg\ViewModel1.prg FileGUID = 27B5EF17-97F1-45CE-AD13-7F2B74E8561D FileType = Code File = %AppPath%\Prg\ValueTextBox.prg FileGUID = 69717E8B-8FCA-4800-9A64-84BE427A20EE FileType = Code [ValueTextBoxApp References] ReferenceGAC = CLR4,System,1,0,4.0.0.0 ReferenceGAC = CLR4,PresentationCore,1,0,4.0.0.0 ReferenceGAC = CLR4,PresentationFramework,1,0,4.0.0.0 ReferenceGAC = CLR4,System.Windows,1,0,4.0.0.0 ReferenceGAC = CLR4,System.Xaml,1,0,4.0.0.0 ReferenceGAC = CLR4,WindowsBase,1,0,4.0.0.0 [ValueTextBoxApp Resources] [ValueTextBoxApp Native Resources] [ValueTextBoxApp License files] [ValueTextBoxApp General Options] Switches= ZeroArrays=0 CaseSensitive=0 ImplicitNamespace=0 VO1=0 VO2=0 VO3=0 VO4=0 VO5=0 VO6=0 VO7=0 VO8=0 VO9=0 VO10=0 VO11=0 VO12=0 VO13=0 VO14=0 VO16=0 LateBound=0 Unsafe=0 IgnoreStdDefs=0 Ovf=0 FOvf=0 ResponseOnly=0 [ValueTextBoxApp Configurations] AppConfig = Debug,11111111-1111-1111-1111-111111111111 Switches= SwitchesCF= CommandLine= CommandLineCF= Debug=1 DebugInit=1 DefineDebug=1 DefineTrace=0 SyntaxOnly=0 WarningsErrors=0 ForceConsole=0 ForceX86=0 AppConfig = Release,22222222-2222-2222-2222-222222222222 Switches= SwitchesCF= CommandLine= CommandLineCF= Debug=0 DebugInit=0 DefineDebug=0 DefineTrace=0 SyntaxOnly=0 WarningsErrors=0 ForceConsole=0 ForceX86=0 ENDApplication = ValueTextBoxApp [FileContents] %#IDE#%File=TEXT,11757B25-6182-49B3-ABC3-DC780295048B using System.Diagnostics [STAThreadAttribute]; function Start( asCmdLine as string[] ) as int local oApp as App try oApp := App{} oApp:Run() catch oException as System.Exception Debug.WriteLine( "error in __ENTITY__ " + oException:ToString() ) end try return 0 %#IDE#%File=TEXT,03CA0BDA-9DDD-4933-97A3-D85C4B39CF9E // Application : WPFSimpleApp // App.prg , Created : 23.06.2016 16:10 // User : Wolfgang #using System #using System.Collections.Generic #using System.Configuration #using System.Windows class App inherit Application protected virtual method OnStartup( e as StartupEventArgs ) as void local oWindow as View1 super:OnStartup(e) AppDomain.CurrentDomain:UnhandledException += AppDomainUnhandledException oWindow := View1{} oWindow:Show() return protect method CloseApplicationHandler() as void self:Shutdown(0) return protected static method AppDomainUnhandledException( Sender as object, e as UnhandledExceptionEventArgs ) as void HandleException( ( Exception ) e:ExceptionObject ) return protected static method HandleException( Ex as Exception ) as void System.Diagnostics.Debug.WriteLine( Ex:ToString() ) return end class %#IDE#%File=TEXT,5EDD6118-218D-4104-A17D-DF1916E39E5C // Application : MVVMApp1 // BindableBase.prg , Created : 26.06.2016 13:58 // User : Wolfgang using System.ComponentModel using System.Runtime.CompilerServices using System.Collections.Generic using System.Diagnostics public abstract class BindableBase implements INotifyPropertyChanged /// /// Baseclass for implementing the INotifyPropertyChanged interface. Here'a sample for using it: /// public string FirstName /// { /// get { return Get(); } /// set { Set(value); } /// } /// protect _properties := Dictionary{} as Dictionary public event PropertyChanged as PropertyChangedEventHandler protected method _Get( [CallerMemberName] name := null as string ) as T /// /// Gets the value of a property /// /// /// /// local value := null as object Debug.Assert( name != null, "name != null" ) if _properties.TryGetValue( name, out value ) if value == null return Default(T) else return (T) value endif // return value == null ? Default(T) : (T)value endif return Default(T) protected method _Set( value as T, [CallerMemberName] name := null as string ) as void /// /// Sets the value of a property /// /// /// /// /// Use this overload when implicitly naming the property // Debug.Print( "passed Name is " + name + ", passed value is " + value.ToString() ) Debug.Assert(name != null, "name != null") if ( Equals( value, _Get(name) ) ) return endif _properties[name] := value OnPropertyChanged( name ) return protected virtual method OnPropertyChanged([CallerMemberName] propertyName := null as string ) as void local handler as PropertyChangedEventHandler handler := self:PropertyChanged if handler != null handler( self, PropertyChangedEventArgs{ propertyName } ) endif return end class %#IDE#%File=TEXT,8FA77A6F-CED1-4F56-9B0E-74896110479D // Application : MVVMApp1 // RelayCommand.prg , Created : 26.06.2016 14:22 // User : Wolfgang using System using System.Windows.Input using System.Diagnostics public class RelayCommand implements ICommand #region Fields protect _oExecute as Action protect _oCanExecute as Predicate #endregion // Fields #region Constructors public constructor( oExecute as Action ) _oExecute := oExecute _oCanExecute := null return public constructor( oExecute as Action, oCanExecute as Predicate ) _oExecute := oExecute _oCanExecute := oCanExecute return #endregion // Constructors #region ICommand Members [DebuggerStepThrough]; public method CanExecute( oParameter as object ) as logic local lReturn as logic if _oCanExecute == null lReturn := true else lReturn := _oCanExecute( oParameter ) endif return lReturn public event CanExecuteChanged as EventHandler add CommandManager.RequerySuggested += VALUE end add remove CommandManager.RequerySuggested -= VALUE end remove end event // { // add { CommandManager.RequerySuggested += value; } // remove { CommandManager.RequerySuggested -= value; } // } public method Execute( oParameter as object ) as void _oExecute( oParameter ) return #endregion // ICommand Members end class %#IDE#%File=TEXT,0A982206-380F-462F-81CF-5AEA4B66CD10 // Application : MVVMApp1 // Data1.prg , Created : 26.06.2016 13:57 // User : Wolfgang // using System.Runtime.CompilerServices class Model1 inherit BindableBase constructor() self:Value1 := "value 1" self:Value2 := 123 return property Value1 as string get super:_Get() set super:_Set( value ) property Value2 as int get super:_Get() set super:_Set( value ) end class %#IDE#%File=TEXT,108B7B2A-F63A-4892-9EDE-8B5C2479842F // Application : WPFSimpleApp // Form1.prg , Created : 23.06.2016 16:10 // User : Wolfgang using System.Windows using System.Windows.Controls using System.Windows.Data class View1 inherit Window constructor() super() self:InitializeComponents() return private method InitializeComponents() as void local oMargin as Thickness local nHeight as int local oGrid as Grid local oLabel as Label local oTextBox as ValueTextBox local oButton as Button local oPanel as StackPanel local oBinding as Binding oMargin := Thickness{ 5 } nHeight := 30 self:Height := 180 self:Width := 400 self:Title := "Form1" oGrid := Grid{} oGrid:ColumnDefinitions:Add( ColumnDefinition{} ) oGrid:ColumnDefinitions:Add( ColumnDefinition{} ) oGrid:RowDefinitions:Add( RowDefinition{} ) oGrid:RowDefinitions:Add( RowDefinition{} ) oGrid:RowDefinitions:Add( RowDefinition{} ) oLabel := Label{} oLabel:Content := "Label 1" oLabel:Name := "Label1" oLabel:Margin := oMargin oLabel:Height := nHeight Grid.SetRow( oLabel, 0 ) Grid.SetColumn( oLabel, 0 ) oGrid:Children:Add( oLabel ) oTextBox := ValueTextBox{} oTextBox:Text := "" oTextBox:Name := "Value1" oTextBox:Margin := oMargin oTextBox:Height := nHeight Grid.SetRow( oTextBox, 0 ) Grid.SetColumn( oTextBox, 1 ) oGrid:Children:Add( oTextBox ) oBinding := Binding{ "Server." + oTextBox:Name } oBinding:ValidatesOnDataErrors := true oBinding:UpdateSourceTrigger := UpdateSourceTrigger.PropertyChanged oTextBox:SetBinding( TextBox.TextProperty, oBinding ) oLabel := Label{} oLabel:Content := "Label 2" oLabel:Name := "Label2" oLabel:Margin := oMargin oLabel:Height := nHeight Grid.SetRow( oLabel, 1 ) Grid.SetColumn( oLabel, 0 ) oGrid:Children:Add( oLabel ) oTextBox := ValueTextBox{} oTextBox:Text := "" oTextBox:Name := "Value2" oTextBox:Margin := oMargin oTextBox:Height := nHeight Grid.SetRow( oTextBox, 1 ) Grid.SetColumn( oTextBox, 1 ) oGrid:Children:Add( oTextBox ) oBinding := Binding{ "Server." + oTextBox:Name } oBinding:ValidatesOnDataErrors := true oBinding:UpdateSourceTrigger := UpdateSourceTrigger.PropertyChanged oTextBox:SetBinding( TextBox.TextProperty, oBinding ) oPanel := StackPanel{} oPanel:Orientation := Orientation.Horizontal oPanel:HorizontalAlignment := HorizontalAlignment.Right oButton := Button{} oButton:Content := "OK" oButton:Name := "OKButton" oButton:Margin := oMargin oButton:Height := nHeight oButton:Padding := oMargin oBinding := Binding{ oButton:Name } oButton:SetBinding( Button.CommandProperty, oBinding ) oPanel:Children:Add( oButton ) oButton := Button{} oButton:Content := "Cancel" oButton:Name := "CancelButton" oButton:Margin := oMargin oButton:Padding := oMargin oButton:Height := nHeight oBinding := Binding{ oButton:Name } oButton:SetBinding( Button.CommandProperty, oBinding ) oPanel:Children:Add( oButton ) Grid.SetRow( oPanel, 2 ) Grid.SetColumn( oPanel, 1 ) oGrid:Children:Add( oPanel ) self:Content := oGrid self:DataContext := ViewModel1{} return end class %#IDE#%File=TEXT,27B5EF17-97F1-45CE-AD13-7F2B74E8561D // Application : MVVMApp1 // ViewModel1.prg , Created : 26.06.2016 13:56 // User : Wolfgang using System.Diagnostics using System.Windows using System.Windows.Input class ViewModel1 inherit BindableBase protect _oServer as Model1 constructor() _oServer := Model1{} self:CancelButton := RelayCommand{ Action{ self, @ProgramExit() } } self:OkButton := RelayCommand{ Action{ self, @SaveData() }, Predicate{ self, @CanSaveData() } } return property Server as Model1 get _oServer set _oServer := value property CancelButton as ICommand get super:_Get() set super:_Set( value ) property OKButton as ICommand get super:_Get() set super:_Set( value ) virtual method ProgramExit( oObject as object ) as void Debug.WriteLine( "Handling Close Window" ) // Application.Current: Application.Current:MainWindow:Close() return virtual method SaveData( oObject as object ) as void Debug.WriteLine( "Handling SaveData" ) MessageBox.Show( String.Format( "Value 1: {0}, Value 2: {1}", _oServer:Value1, _oServer:Value2:ToString() ) ) Application.Current:MainWindow:Close() return virtual method CanSaveData( oObject as object ) as logic local lReturn as logic Debug.WriteLine( "Handling CanSaveData" ) if String.IsNullOrEmpty( _oServer:Value1 ) .or. _oServer:Value2 == 0 lReturn := false else lReturn := true endif return lReturn end class %#IDE#%File=TEXT,69717E8B-8FCA-4800-9A64-84BE427A20EE // Application : ValueTextBoxApp // ValueTextBox.prg , Created : 26.12.2017 14:25 // User : wolfgang using System.Windows.Controls using System.Windows using System.Reflection #region Class declaration class ValueTextBox inherit TextBox protect _oValue as object protect _oValueType as Type protect _cTextValue as string public static initonly ValueProperty as DependencyProperty #endregion #region Constructors static constructor() ValueTextBox.ValueProperty := DependencyProperty.Register( "ValueProperty", TypeOf( object ), TypeOf( ValueTextBox ), ; UIPropertyMetadata{ null, PropertyChangedCallback{ ValuePropertyChanged } } ) return constructor() self:LostFocus += RoutedEventHandler{ self , @LostFocusHandler() } return #endregion #region Callbacks for DependencyProperty implementation static method ValuePropertyChanged( d as DependencyObject, e as DependencyPropertyChangedEventArgs ) as void local oTextBox as ValueTextBox local oValue as object oTextBox := ( ValueTextBox ) d oValue := ( object ) e:NewValue oTextBox:_Value := oValue return #endregion #region Properties property value as object get self:GetValue( ValueTextBox.ValueProperty ) set self:SetValue( ValueTextBox.ValueProperty, value ) property _Value as object get _oValue set _oValue := value, self:_SetType( _oValue ) new property Text as string get super:Text set _cTextValue := value, super:Text := _cTextValue #endregion #region Eventhandlers method LostFocusHandler( oSender as object , oArgs as RoutedEventArgs ) as void self:__Update() return #endregion #region internal implementation private method _SetType( oValue as object ) as void local oDateTime as DateTime local oDateTimeN as DateTime? _oValueType := oValue:GetType() do case case _oValueType:Equals( TypeOf( DateTime ) ) oDateTime := ( dateTime ) oValue if oDateTime:Hour == 0 .and. oDateTime:Minute == 0 .and. oDateTime:Second == 0 self:Text := oDateTime:ToShortDateString() else self:Text := oDateTime:ToString() endif case _oValueType:Equals( TypeOf( DateTime? ) ) oDateTimeN := ( dateTime? ) oValue if oDateTimeN:HasValue oDateTime := ( DateTime ) oDateTimeN if oDateTime:Hour == 0 .and. oDateTime:Minute == 0 .and. oDateTime:Second == 0 self:Text := oDateTime:ToShortDateString() else self:Text := oDateTime:ToString() endif else self:Text := "" endif otherwise self:Text := oValue:ToString() endcase return private method __Update() as void local oValue as object local oInfo as System.Reflection.MethodInfo local lSuccess as logic local aParameters as object[] local cTextValue as string local aTypes as System.Type[] try if _oValueType == null System.Diagnostics.Debug.WriteLine( "no _oValueType assigned" ) else aTypes := { TypeOf( string ), ( ( System.Type ) _oValueType ):MakeByRefType() } oInfo := _oValueType:GetMethod( "TryParse", aTypes ) if oInfo != null cTextValue := self:Text oValue := null aParameters := { cTextValue, oValue } lSuccess := ( logic ) oInfo:Invoke( null, aParameters ) if lSuccess oValue := aParameters[__ARRAYBASE__+1] self:Value := oValue _cTextValue := cTextValue else self:Text := _cTextValue endif endif endif catch oEx as Exception MessageBox.Show( oEx:Message + e"\n" + oEx:StackTrace ) end try return #endregion end class