In my windows phone application, I have a LoadMore button in one page. The loadmore button is defined in style
in <phone:PhoneApplicationPage.Resources>
section. I have 2 listboxes in that page and uses the same style for both of the listboxes. When I click on the loadmore button, how can I identify the LoadMore button in which listbox raise the event?
<phone:PhoneApplicationPage.Resources>
<Style x:Key="ListBoxStyle" TargetType="ListBox">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Visible"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<ScrollViewer x:Name="ScrollViewer">
<StackPanel>
<ItemsPresenter/>
<Button Content="Load More..." Name="btnLoadMore" Visibility="Visible" Background="White" Foreground="#FF176DDC" Click="btnLoadMore_Click"></Button>
</StackPanel>
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</phone:PhoneApplicationPage.Resources>
How can I find the button in which listbox is clicked?
To have that kind of functionality in a style in my opinion is the wrong approach. Try putting the
ListBox
and theButton
into aUserControl
, that itself exposes an event for loading more data. Internally you then handle theClick
-event of the button and raise theUserControl
'sLoadMore
-event.