0
Answer

How to select the individual image and then click the button

Manoharan

Manoharan

10y
570
1
Hi,
How to select the individual image and then click the button,need to send the selected image value?

   Each rectangle inside i added image control.when click the submit button,send the image value ,which image i select.How to select the image.Here image selection is not working.please help me.(wpf using mvvm)


SampleView.xaml:

<UserControl x:Class="GameDealModule.View.SampleView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"
           d:DesignHeight="600" d:DesignWidth="1241" >

    <Grid Background="Gray" HorizontalAlignment="Center" VerticalAlignment="Center">
        <Canvas HorizontalAlignment="Left" Height="600" Margin="29,10,0,0" VerticalAlignment="Top" Width="1241">

            <Rectangle Height="209" Width="150" Canvas.Left="41" Stroke="Black" Canvas.Top="21"></Rectangle>          
              
            <Image Height="209" Width="150" Source="../Images/nature.png" Canvas.Left="41" Canvas.Top="21"></Image>           
          


            <Rectangle Height="209" Width="150" Canvas.Left="206" Stroke="Black" Canvas.Top="21" ></Rectangle>
          
            <Image Height="209" Width="150" Source="../Images/flower.png" Canvas.Left="206" Canvas.Top="21"></Image>


         <Button Content="Submit" Canvas.Left="372" Canvas.Top="533" Width="103" Height="37" Command="{Binding SubmitCommand}"/>
            <Button Content="Close" Canvas.Left="489" Canvas.Top="533" Width="103" Height="37" Command="{Binding CloseCommand}"/>

        </Canvas>
    </Grid>
</UserControl>

SampleView.xaml.cs:
 public partial class SampleView: UserControl
    {
        public SampleView()
        {
            InitializeComponent();
            this.DataContext = new SampleViewModel();
        }
    }

SampleViewModel.cs:
 public class SampleViewModel: INotifyPropertyChanged
    {
        public SampleViewModel()
        {
           
            this.SubmitCommand = new DelegateCommand<object>(this.OnSubmit, this.CanSubmit);

        }
        private bool CanSubmit(object arg)
        {
            return true;
        }


        private void OnSubmit(object arg)
        {
               string selectedimage="";

    }
      public ICommand SubmitCommand { get; private set; }
      

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

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

        #endregion
    }