Quantcast
Viewing all articles
Browse latest Browse all 18858

facing problem in binding image path in textbox through mvvm

hi , i am new to mvvm i try to bind image using mvvm but fail to do so

my xaml

<TextBox x:Name="Ecgimagepath" Text="{Binding ImagePath, UpdateSourceTrigger=PropertyChanged}" Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="4" HorizontalAlignment="Left" Width="655" ></TextBox><Button x:Name="browse" Grid.Row="4"  Grid.Column="4" HorizontalAlignment="Right" Width="73" Command="{Binding BrowseImageCommand}" Height="20" Content="Browse" />

my model class

   class ECGImageModel:INotifyPropertyChanged
    {
        private string imagePath;

        public string ImagePath
        {
            get { return imagePath; }
            set
            {
                imagePath = value;
                OnPropertyChanged("ImagePath");
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

    }

my view model

private ICommand _BrowseImageCommand; public ICommand BrowseImageCommand //Binding to Button { get { return _BrowseImageCommand; } set { _BrowseImageCommand = value; } } public void executebrowseimage() { ECGImageModel eim = new ECGImageModel(); OpenFileDialog op = new OpenFileDialog(); op.Title = "Select a picture"; op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +"JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +"Portable Network Graphic (*.png)|*.png"; if (op.ShowDialog() == true) { //Ecg_Image.Source = new BitmapImage(new Uri(op.FileName)); string filename = op.FileName; //imagepathe.Add(new ECGImageModel { ImagePath = filename }); eim.ImagePath = filename; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("ImagePath")); } }

my realycommand class

 public class RelayCommand:ICommand
    {
        #region ICommand Members

        private Action _handler;
        public RelayCommand(Action handler)
        {
            _handler = handler;
        }

        public bool CanExecute(object parameter)
        {
            return true;
        }
        public event EventHandler CanExecuteChanged;
        public void Execute(object parameter)
        {
            _handler();
        }

        #endregion
    } !!!!!!!!1here binding this constructor !!!!!!!! NewECGConfigurationViewModel() to data context . public NewECGConfigurationViewModel() { GetECGFeatureRecord(); UploadCommand = new RelayCommand(ExecuteOpenFileDialog); BrowseImageCommand = new RelayCommand(executebrowseimage); }

my dialog box get open but the image path is not binding on the textbox



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>