Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SampleView.xaml:

<usercontrol x:class="GameDealModule.View.SampleView" xmlns:x="#unknown">
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 removed="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">

<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">

<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>



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
}
Posted

1 solution

Hi,

I don't think Image is having selected property, you can use radio button instead and edit its template with the images. So you can select only one image at a time (if your scenario allows multiselect means you may need to use any other controls).

Xaml code will be like this,
XML
<RadioButton x:Name="nature" Height="100" Width="100">
            <RadioButton.Template>
                <ControlTemplate>
                    <Image Height="100" Width="100" Source="../Images/images.jpg" HorizontalAlignment="Center"/>
                </ControlTemplate>
            </RadioButton.Template>
        </RadioButton>


And in the behavior of RadioButton, at the Checked event, you can set the SelectedImage property of ViewModel with the radiobutton name. To know about behavior go to this link.

Hope it helps you.

Regards,
Karuppasamy P
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900