如何在列表框的末尾添加“更多”按钮并在代码隐藏后处理它? [英] How to add a `more` button on the end of a listbox and handle it on code-behind?

查看:102
本文介绍了如何在列表框的末尾添加“更多”按钮并在代码隐藏后处理它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


< p style ="border-width:0px; margin:0px 0px 1em; padding:0px; text-align:left; line-height:18px; clear:both; font-family:Arial," Liberation Sans"," DejaVu Sans",sans-serif; font-size:14px; vertical-align:baseline; word-wrap:break-word">
 

 


我将此资源添加到  App.xaml

<Style x:Key="ListBoxMore" TargetType="ListBox">
   
<Setter Property="Background" Value="Transparent"/>
   
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
   
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
   
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
   
<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" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}" Padding="{TemplateBinding Padding}">
                   
<StackPanel>
                       
<ItemsPresenter/>
                       
<Button Content="More" Name="moreButton"></Button>
                   
</StackPanel>
               
</ScrollViewer>
           
</ControlTemplate>
       
</Setter.Value>
   
</Setter>
</Style>



我的列表框添加了这种风格

And my listbox adds this style

Style="{StaticResource ListBoxMore}"



它有效,但问题是......

And it works, but the question is...


我如何  在代码隐藏中获取此按钮?我需要为此按钮添加属性,处理点击,如何获得此按钮?

How can I get this button in the code-behind? I need to add properties to this button and handle the click, how do I get this button?

 

Windows Phone 7 » XAML

Windows Phone 7 » XAML

Stack Overflow问题:
http://stackoverflow.com/q/7705216/340760

Question on Stack Overflow: http://stackoverflow.com/q/7705216/340760

c#  |
xaml   |

c# | xaml | listbox

推荐答案

好的,我是在Windows7 并且没有VS 11在我面前,所以请原谅我,如果我的答案是错误的。

OK, I'm in Windows7 and don't have VS 11 in front of me, so forgive me if my answer is wrong.

 

好的,我想你可以抓住Listbox的ApplyTemplate方法并找到StackPanel(你需要先命名)e视觉树中的抒情。现在你可以添加任何你想要的东西了!

OK, I guess you can catch on ApplyTemplate method for the Listbox and find the StackPanel (you need to name it first) element in the visual tree. And now you can add anything you want to!


这篇关于如何在列表框的末尾添加“更多”按钮并在代码隐藏后处理它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆