Posts

Showing posts with the label WPF

[Code snippet] INotifyPropertyChanged in the model and subscribed the PropertyChanged event of the model in ViewModel

internal class Model:INotifyPropertyChanged { public Model() { } string _FirstName = " Shahir" ; public string FirstName { get { return _FirstName; } set { _FirstName = value ; OnPropertyChanged(); } } public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged([CallerMemberName] string propertyName = " " ) { if (PropertyChanged!= null ) { PropertyChanged( this , new PropertyChangedEventArgs(propertyName)); } } } internal class MyViewModel:INotifyPropertyChanged { private Model myModel; public MyViewModel(Model model) { this .myModel = model; myModel.PropertyChanged += myModel_PropertyChanged; } public event Property...

Code Snippet: Read ArcGIS Offline Geodatabase into ArcGIS Runtime in WPF

Here is an quick code snippet for loading ArcGIS runtime database ( offline database) in .NET in ESRI Runtime version 100. The OverlayFeatureLayers() reads the layers from runtime geodatabase and overlayes on runtime environment map in Web Mercator Projection (EPSG: 3857) using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Runtime.CompilerServices; using System.Windows.Input; using Esri.ArcGISRuntime.Data; using Esri.ArcGISRuntime.Geometry; using Esri.ArcGISRuntime.Location; using Esri.ArcGISRuntime.Mapping; using Esri.ArcGISRuntime.Security; using Esri.ArcGISRuntime.Symbology; using Esri.ArcGISRuntime.Tasks; using Esri.ArcGISRuntime.UI; using ReadRuntimeGeodatabase.CustomViewModelBase; namespace ReadRuntimeGeodatabase { public class MapViewModel : ViewModelBase { public MapViewModel() { OverlayFeatu...

Prevent WPF Global Keyboard Hook from stops working after hitting keys a while C# .NET

Image
The article written by Dylan Currier,  Low Level Global Keyboard Hook / Sink in C# .NE T is one the simple, easily understandable, and and working post on Global Keyboard hook out there in internet. It worked in my WPF application and I added following line in the WPF app to refresh hook after each key press- IDK  if it is write or wrong, more likely to be a wrong practice to hook/unhook every time but it gets the job done. The primary reason to refresh hook is to prevent app hanging (not responding to the key press) after few clicks on the WPF button. void _listener_OnKeyPressed(object sender, KeyPressedArgs e)         {                       _listener.UnHookKeyboard();           _listener.HookKeyboard();         } Following is the video from  Dylan Currier   on  Low Level Keyboard Hook in C# / .NET"

Code snippet: Open Folder Browser Dialog in WPF

Install WPFFolderBrowser 1.0.2 from nuget gallery to use the Windows Vista / Windows 7 Folder Browser Dialog from your WPF projects, without any additional dependencies. Install-Package WPFFolderBrowser then import WPFFolderBrowser using  WPFFolderBrowser; private   void  BrowseFolder()         {              WPFFolderBrowserDialog  dd =  new   WPFFolderBrowserDialog ();              var  result = dd.ShowDialog();              if  (result.HasValue)             {                 TxtFvsAccessDbPath = dd.FileName;         ...

Code snippet: WPF UWP ListView SelectionChanged Event Handling in ViewModel

Solution from  Dhaval Patel  in Sliverlight application works perfectly on my WPF application. I prefer his idea because it is more clear and cleaner than other solutions that  I have came with. The event handling approach explained as -" This is the way where You can Reach the Selection changed events in Your MVVM Application First Of all i tell you that Command Property only work in Button now we have to Explicitly binding that property in our Selection Changed event like List box or combo box in Your XMAL file" <ListBox Name = "MyListBox" ItemsSource = "{Binding ListItems}" Height = "150" Width = "150" Margin = "281,32,-31,118" > <Local:Interaction.Triggers> <Local:EventTrigger EventName = "SelectionChanged" > <Local:InvokeCommandAction Command = "{Binding MyCommand}" CommandParameter = "{Binding ElementName=MyListBox,Path=Selec...

Code snippet: Data binding between ViewModel and Radio Button in WPF

Image
Following example shows the data binding between radio buttons and ViewModel in WPF. Parts of View.xaml <Grid.Resources> <Utilities:RadioHelper x:Key= "RadioConverter" /> <Utilities:RadioHelper x:Key= "InverseRadioConverter" Inverse= "True" /> </Grid.Resources> <RadioButton Name= "radFvsOracle" GroupName= "fvsStorage" Content= "Oracle" Margin= "7,0,0,0" IsChecked= "{Binding Path=RadFvsResults, Converter= {StaticResource ResourceKey=RadioConverter}}" ></RadioButton> <RadioButton Name= "radFvsAccess" GroupName= "fvsStorage" Content= "Access" Grid.Column= "2" Margin= "11,0,0,0" IsChecked= "{Binding Path=RadFvsResults, Converter= {StaticResource ResourceKey=InverseRadioConverter}}" ></RadioButton> Parts of  RadioHelper.cs public class RadioHelper :IValueConver...

Multi-item Selection WPF ListBox using Attached Property

The attached property class looks like - ListBoxHelper.cs 1: public static class ListBoxHelper 2: { 3: public static readonly DependencyProperty SelectedItems Property = 4: DependencyProperty.RegisterAttached("SelectedItems", 5: typeof(IList), 6: typeof(ListBoxHelper), 7: new PropertyMetadata(default(List<string>), 8: OnSelectedItemsChanged)); 9: 10: public static IList GetSelectedItems(DependencyObject d) 11: { 12: return (IList)d.GetValue(SelectedItemsProperty); 13: } 14: 15: public static void SetSelectedItems(DependencyObject d, IList value) 16: { 17: d.SetValue(SelectedItemsProperty,value); 18: } 19: 20: private static void OnSelectedItemsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 21: { 22: var...

Databind between View and ViewModel for PasswordBox WPF

"When you try to databind the password property of a PasswordBox you will recognize that you cannot do data binding on it. The reason for this is, that the password property is not backed by a DependencyProperty. The reason is databinding passwords is not a good design for security reasons and should be avoided. But sometimes this security is not necessary, then it's only cumbersome that you cannot bind to the password property. In this special cases you can take advantage of the following PasswortBoxHelper. The PasswordHelper is attached to the password box by calling the PasswordHelper.Attach property. The attached property PasswordHelper.Password provides a bindable copy of the original password property of the PasswordBox control." Published on - http://www.wpftutorial.net/PasswordBox.html http://blog.functionalfun.net/2008/06/wpf-passwordbox-and-data-binding.html PasswordHelper.cs 1: public static class PasswordHelper 2: { 3: public...