locked
How to add a `more` button on the end of a listbox and handle it on code-behind? RRS feed

  • Question

  •  

    I added this resource on 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

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

     |  |


    • Edited by BrunoLM Sunday, October 9, 2011 5:58 PM
    Sunday, October 9, 2011 5:57 PM

All replies

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

     

    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!


    Sameer V.
    Monday, October 10, 2011 2:43 PM
  • You can achieve that simply by setting ItemTemplate of custom control.

    I think Modifing ControlTemplate would let listbox lost the ability of Virtualization.

    Thursday, March 29, 2012 7:27 AM