Image not getting the Class ID - Xamarin Forms
I have several images in my XAML as follows (for this example I included two images).
<StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image1" ClassId="Binding Image1" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Asian Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0"
TextColor="StaticResource greyishBrown"/>
</StackLayout>
StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image2" ClassId="Binding Image2" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Japanese Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0"
TextColor="StaticResource greyishBrown"/>
</StackLayout>
I want to check what image has been clicked by the user. Fort this I'm using ClassId. I have included ClassIds in all images. This has a single method in code behind and I'm accessing classId from there.
But I'm not getting the Id when user clicks an image. I'm new to C# and Xamarin Forms. Could someone help me.
public void SelectedImage(object sender, EventArgs eventArgs)
Image image = (Image)sender;
string imageString = image.ClassId;
DisplayAlert("Test", imageSender.ClassId,"OK");
//TODO
c# xamarin xamarin.forms
add a comment |
I have several images in my XAML as follows (for this example I included two images).
<StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image1" ClassId="Binding Image1" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Asian Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0"
TextColor="StaticResource greyishBrown"/>
</StackLayout>
StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image2" ClassId="Binding Image2" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Japanese Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0"
TextColor="StaticResource greyishBrown"/>
</StackLayout>
I want to check what image has been clicked by the user. Fort this I'm using ClassId. I have included ClassIds in all images. This has a single method in code behind and I'm accessing classId from there.
But I'm not getting the Id when user clicks an image. I'm new to C# and Xamarin Forms. Could someone help me.
public void SelectedImage(object sender, EventArgs eventArgs)
Image image = (Image)sender;
string imageString = image.ClassId;
DisplayAlert("Test", imageSender.ClassId,"OK");
//TODO
c# xamarin xamarin.forms
@Gerald Versluis - Could you please look at this?
– apple_92
Nov 12 at 3:39
are Image1 and Image2 string properties on your BindingContext?
– Jason
Nov 12 at 4:13
No. Could you please help me to fix this?
– apple_92
Nov 12 at 4:30
if you just want to assign a static value to ClassID, then just use a string "Image1" or "Image2". If you want to actually bind ClassID to a value on your model, then you will need to specify the name of a public property in the binding expression
– Jason
Nov 12 at 4:33
I removed that and added as ClassId="Image2" , now I'm getting cast error. Not working
– apple_92
Nov 12 at 5:15
add a comment |
I have several images in my XAML as follows (for this example I included two images).
<StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image1" ClassId="Binding Image1" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Asian Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0"
TextColor="StaticResource greyishBrown"/>
</StackLayout>
StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image2" ClassId="Binding Image2" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Japanese Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0"
TextColor="StaticResource greyishBrown"/>
</StackLayout>
I want to check what image has been clicked by the user. Fort this I'm using ClassId. I have included ClassIds in all images. This has a single method in code behind and I'm accessing classId from there.
But I'm not getting the Id when user clicks an image. I'm new to C# and Xamarin Forms. Could someone help me.
public void SelectedImage(object sender, EventArgs eventArgs)
Image image = (Image)sender;
string imageString = image.ClassId;
DisplayAlert("Test", imageSender.ClassId,"OK");
//TODO
c# xamarin xamarin.forms
I have several images in my XAML as follows (for this example I included two images).
<StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image1" ClassId="Binding Image1" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Asian Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0"
TextColor="StaticResource greyishBrown"/>
</StackLayout>
StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image2" ClassId="Binding Image2" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Japanese Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0"
TextColor="StaticResource greyishBrown"/>
</StackLayout>
I want to check what image has been clicked by the user. Fort this I'm using ClassId. I have included ClassIds in all images. This has a single method in code behind and I'm accessing classId from there.
But I'm not getting the Id when user clicks an image. I'm new to C# and Xamarin Forms. Could someone help me.
public void SelectedImage(object sender, EventArgs eventArgs)
Image image = (Image)sender;
string imageString = image.ClassId;
DisplayAlert("Test", imageSender.ClassId,"OK");
//TODO
c# xamarin xamarin.forms
c# xamarin xamarin.forms
edited Nov 11 at 18:01
asked Nov 11 at 17:36
apple_92
6110
6110
@Gerald Versluis - Could you please look at this?
– apple_92
Nov 12 at 3:39
are Image1 and Image2 string properties on your BindingContext?
– Jason
Nov 12 at 4:13
No. Could you please help me to fix this?
– apple_92
Nov 12 at 4:30
if you just want to assign a static value to ClassID, then just use a string "Image1" or "Image2". If you want to actually bind ClassID to a value on your model, then you will need to specify the name of a public property in the binding expression
– Jason
Nov 12 at 4:33
I removed that and added as ClassId="Image2" , now I'm getting cast error. Not working
– apple_92
Nov 12 at 5:15
add a comment |
@Gerald Versluis - Could you please look at this?
– apple_92
Nov 12 at 3:39
are Image1 and Image2 string properties on your BindingContext?
– Jason
Nov 12 at 4:13
No. Could you please help me to fix this?
– apple_92
Nov 12 at 4:30
if you just want to assign a static value to ClassID, then just use a string "Image1" or "Image2". If you want to actually bind ClassID to a value on your model, then you will need to specify the name of a public property in the binding expression
– Jason
Nov 12 at 4:33
I removed that and added as ClassId="Image2" , now I'm getting cast error. Not working
– apple_92
Nov 12 at 5:15
@Gerald Versluis - Could you please look at this?
– apple_92
Nov 12 at 3:39
@Gerald Versluis - Could you please look at this?
– apple_92
Nov 12 at 3:39
are Image1 and Image2 string properties on your BindingContext?
– Jason
Nov 12 at 4:13
are Image1 and Image2 string properties on your BindingContext?
– Jason
Nov 12 at 4:13
No. Could you please help me to fix this?
– apple_92
Nov 12 at 4:30
No. Could you please help me to fix this?
– apple_92
Nov 12 at 4:30
if you just want to assign a static value to ClassID, then just use a string "Image1" or "Image2". If you want to actually bind ClassID to a value on your model, then you will need to specify the name of a public property in the binding expression
– Jason
Nov 12 at 4:33
if you just want to assign a static value to ClassID, then just use a string "Image1" or "Image2". If you want to actually bind ClassID to a value on your model, then you will need to specify the name of a public property in the binding expression
– Jason
Nov 12 at 4:33
I removed that and added as ClassId="Image2" , now I'm getting cast error. Not working
– apple_92
Nov 12 at 5:15
I removed that and added as ClassId="Image2" , now I'm getting cast error. Not working
– apple_92
Nov 12 at 5:15
add a comment |
1 Answer
1
active
oldest
votes
XAML
<StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image1" ClassId="Image1" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Asian Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0" TextColor="StaticResource greyishBrown" />
</StackLayout>
<StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image2" ClassId="Image2" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Japanese Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0" TextColor="StaticResource greyishBrown"
/>
</StackLayout>
C#
public void SelectedImage(object sender, EventArgs eventArgs)
Image image = (Image)sender;
string imageString = image.ClassId;
DisplayAlert("Test", imageString ,"OK");
//TODO
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251397%2fimage-not-getting-the-class-id-xamarin-forms%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
XAML
<StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image1" ClassId="Image1" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Asian Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0" TextColor="StaticResource greyishBrown" />
</StackLayout>
<StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image2" ClassId="Image2" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Japanese Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0" TextColor="StaticResource greyishBrown"
/>
</StackLayout>
C#
public void SelectedImage(object sender, EventArgs eventArgs)
Image image = (Image)sender;
string imageString = image.ClassId;
DisplayAlert("Test", imageString ,"OK");
//TODO
add a comment |
XAML
<StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image1" ClassId="Image1" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Asian Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0" TextColor="StaticResource greyishBrown" />
</StackLayout>
<StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image2" ClassId="Image2" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Japanese Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0" TextColor="StaticResource greyishBrown"
/>
</StackLayout>
C#
public void SelectedImage(object sender, EventArgs eventArgs)
Image image = (Image)sender;
string imageString = image.ClassId;
DisplayAlert("Test", imageString ,"OK");
//TODO
add a comment |
XAML
<StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image1" ClassId="Image1" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Asian Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0" TextColor="StaticResource greyishBrown" />
</StackLayout>
<StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image2" ClassId="Image2" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Japanese Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0" TextColor="StaticResource greyishBrown"
/>
</StackLayout>
C#
public void SelectedImage(object sender, EventArgs eventArgs)
Image image = (Image)sender;
string imageString = image.ClassId;
DisplayAlert("Test", imageString ,"OK");
//TODO
XAML
<StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image1" ClassId="Image1" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Asian Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0" TextColor="StaticResource greyishBrown" />
</StackLayout>
<StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image2" ClassId="Image2" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Japanese Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0" TextColor="StaticResource greyishBrown"
/>
</StackLayout>
C#
public void SelectedImage(object sender, EventArgs eventArgs)
Image image = (Image)sender;
string imageString = image.ClassId;
DisplayAlert("Test", imageString ,"OK");
//TODO
answered Nov 12 at 7:04
Mustafa Mohammed Eldkhri
161
161
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251397%2fimage-not-getting-the-class-id-xamarin-forms%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
@Gerald Versluis - Could you please look at this?
– apple_92
Nov 12 at 3:39
are Image1 and Image2 string properties on your BindingContext?
– Jason
Nov 12 at 4:13
No. Could you please help me to fix this?
– apple_92
Nov 12 at 4:30
if you just want to assign a static value to ClassID, then just use a string "Image1" or "Image2". If you want to actually bind ClassID to a value on your model, then you will need to specify the name of a public property in the binding expression
– Jason
Nov 12 at 4:33
I removed that and added as ClassId="Image2" , now I'm getting cast error. Not working
– apple_92
Nov 12 at 5:15