在我的Windows Phone应用程序中,我在一个页面中有一个LoadMore按钮。 loadmore按钮在style
部分的<phone:PhoneApplicationPage.Resources>
中定义。我在该页面中有2个列表框,并对两个列表框使用相同的样式。当我点击loadmore按钮时,如何识别列表框引发事件的LoadMore按钮?
<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>
如何找到单击列表框的按钮?
答案 0 :(得分:1)
在我看来,在某种风格中使用这种功能是错误的做法。尝试将ListBox
和Button
放入UserControl
,它本身会公开一个用于加载更多数据的事件。
在内部,您可以处理按钮的Click
- 事件并提升UserControl
的{{1}} - 事件。