My mockup is below. Here's the issue: if the button is in the selected row, then clicking the button will do anything I need it to with the Item bound to that row. If I click a button in a row OTHER THAN the selected row, then I can still only do things with the Item in the selected row. I need to be able to reference rows that aren't selected if the user clicks a button in that row instead of the selected row.
MainPage.xaml:
<Page
x:Class="ProblemExample.MainPage"
xmlns="http://ift.tt/w9rHWX;
xmlns:x="http://ift.tt/zZkFEV;
xmlns:local="using:ProblemExample"
xmlns:d="http://ift.tt/PuXO1J;
xmlns:mc="http://ift.tt/R4RR6u;
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel Orientation="Vertical">
<TextBlock x:Name="ResultText" Text="Result Text" />
<ListView x:Name="ProblemList">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock x:Name="BoundText1" Grid.Row="0" Grid.Column="0" Text="{Binding Data1}" />
<TextBlock x:Name="BoundText2" Grid.Row="0" Grid.Column="1" Text="{Binding Data2}" />
<Button x:Name="ProblemButton" Grid.Row="0" Grid.Column="2" Content="Problem" Click="ProblemButton_Click" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
</Grid>
</Page>
MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at http://ift.tt/14RBJ0z
namespace ProblemExample
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
List<SampleData> sample = new List<SampleData>();
for (int i = 1; i <=6; i++)
{
string dat1 = "data1" + i.ToString();
string dat2 = "data2" + i.ToString();
sample.Add(new SampleData()
{
Data1 = dat1,
Data2 = dat2
});
}
ProblemList.ItemsSource = sample;
}
private void ProblemButton_Click(object sender, RoutedEventArgs e)
{
string selectedInd = ProblemList.SelectedIndex.ToString();
//string controlInd = (Button)sender.something? <---this is my problem
ResultText.Text = "Index of selected row is " + selectedInd;
}
}
public class SampleData
{
public string Data1 { get; set; }
public string Data2 { get; set; }
}
}
No comments:
Post a Comment