Button Click Parameter
I am new to Windows Metro Apps and am struggling immensely. I have a
datatemplate which binds to an object with a few properties. I have
implemented the INotifyPropertyChanged in the ViewModel where I use a
property of ObservableCollection. This DataTemplate is used in my listView
to display a list of DemoItems. I have added the Edit Button in there
because when clicked I want to navigate to an "Edit Page" where I can
configure the Data Item. My question is how can I pass the "ID" property
on the button click to the code behind? Since the ID is databound it is
available in the Template but I cannot find a way to link it to the button
and I also do not want to use the lvDemoItems_SelectionChanged event to
first select the item. The button should be aware of the ID property. Any
help would be appreciated. Thanks
public class DemoItem
{
public int ID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Owner { get; set; }
public string ImageURI { get; set; }
public DemoItem(int id, string name, string description, string owner,
string imageURI)
{
this.ID = id;
this.Name = name;
this.Description = description;
this.Owner = owner;
this.ImageURI = imageURI;
}
}
<DataTemplate x:Name="DemoTemplate">
<Grid Height="110"
Width="480"
Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border Background="{StaticResource
ListViewItemPlaceholderBackgroundThemeBrush}"
Width="110"
Height="110">
<Image Source="{Binding ImageURI}"
Stretch="UniformToFill"
AutomationProperties.Name="{Binding Title}" />
</Border>
<StackPanel Grid.Column="1"
VerticalAlignment="Top"
Margin="10,0,0,0">
<TextBlock Text="{Binding Name}"
Style="{StaticResource TitleTextStyle}"
TextWrapping="NoWrap" />
<TextBlock Text="{Binding Description}"
Style="{StaticResource BodyTextStyle}"
MaxHeight="160" />
<Button Content="Edit"
BorderBrush="Black"
Background="Green"
Height="40"
Width="80"
Margin="0,20,0,0"
Click="Button_Click_4"></Button>
</StackPanel>
</Grid>
</DataTemplate>
No comments:
Post a Comment