I'm trying to make a funny comic/meme app like funnyjunk.com, which contains a dislike and a like buttons on every comic, like this : http://s9.postimg.org/ikiyo7iy7/funnyjunk.png
My problem is: I can't get access to code the dislike/like buttons inside the DataTemplate from code behind. Is there any way to access buttons inside DataTemplate?
I'm using ListView in this case, and here is how my DataTemplate looks like :
<stackpanel horizontalalignment="Center" verticalalignment="Center" orientation="Vertical">
<stackpanel>
<Image Source="{Binding Image}" Height="600" Width="800" Stretch="UniformToFill"/>
</stackpanel>
<stackpanel horizontalalignment="Center" orientation="Horizontal">
<Button x:Name="blike" Content="L" FontSize="70" HorizontalAlignment="Center" VerticalAlignment="Center" Click="blike_Click"/>
<textblock x:name="tblrate" text="0" fontsize="70" horizontalalignment="Center" verticalalignment="Center" xmlns:x="#unknown" />
<Button x:Name="bdislike" Content="D" FontSize="70" HorizontalAlignment="Center" VerticalAlignment="Center" Click="bdislike_Click"/>
</stackpanel>
</stackpanel>
and Here is the codes for the buttons:
private void blike_Click(object sender, RoutedEventArgs e)
{
int rate = Convert.ToInt16(tblrate.Text);
rate += 1;
tblrate.Text = Convert.ToString(rate);
}
private void bdislike_Click(object sender, RoutedEventArgs e)
{
int rate = Convert.ToInt16(tblrate.Text);
rate -= 1;
tblrate.Text = Convert.ToString(rate);
}
Here's my DataContext (I named it "DataSource"):
public class DataSource
{
public int ID { get; set; }
public string Title { get; set; }
public string Image { get; set; }
public DataSource(int _ID, string _Image, string _Title)
{
ID = _ID;
Image = _Image;
Title = _Title;
}
}
public class DataFill
{
public List<DataSource> Comics= new List<DataSource>();
public void MainPageComics()
{
Comics.Add(new DataSource(1, "/Assets/Comic1.jpg", "Jokur and Botmon"));
Comics.Add(new DataSource(2, "/Assets/Comic2.jpg", "Jokur and Botmon2"));
}
}
What I'm trying to achieve is:
1. The dislike/like buttons to work in EACH and every comic that is BOUND inside the ListView, so it will change the value of the dislike/like RATE of the comic.
What I have tried:
1. Jerry Nixon's tutorial (it only works for textbox not textblock, i don't understand why)
2. I'm still trying to understand to use the Command property, which is very complex.
still looking for tutorials to use ICommands, if you have a tutorial video that would be very helpful.
I'm working on a METRO app btw, thank you in advance.