数据绑定列表框和按钮一的ScrollViewer / StackPanel的构造内,巴顿出现下面的列表框内容结束巴顿、列表、绑定、按钮

2023-09-03 06:35:44 作者:白天不懂夜的黑 ˉ

我有下面的结构,它显示了一个数据绑定列表框和内部的StackPanel中,它再次被放置在一个ScrollViewer的一个按钮:

 <的ScrollViewer VerticalScrollBarVisibility =可见
                  高度=400>
        < StackPanel的方向=垂直
                    了maxHeight =400>
            < ListBox的X:名称=LbTelEntries
                     的SelectionChanged =LbTelEntries_SelectionChanged
                     =了maxHeight340
                     VerticalAlignment =热门
                     的ItemsSource ={绑定路径= TelItems}>
                < ListBox.ItemTemplate>
                    <的DataTemplate>
                        <模板:ListBoxItemTemplateSelector内容={结合}/>
                    < / DataTemplate中>
                < /ListBox.ItemTemplate>
            < /列表框>
            <按钮X:名称=BtMoreTelEntries
                    内容=更多结果
                    点击=BtMoreTelEntries_Click
                    能见度={绑定路径= NumberRemainingResults,转换器= {的StaticResource NullToVisConverter}}
                    的Horizo​​ntalAlignment =中心
                    VerticalAlignment =底
                    身高=70
                    宽度=410
                    余量=0 0 0 0
                    >< /按钮>
        < / StackPanel的>
    < /的ScrollViewer>
 

我的问题是,该按钮只应出现在列表框滚动到结束。一旦按钮被点击,列表框的内容交换和按钮应该再次移动到列表框的结尾......

我将如何做到这一点?

编辑: 我要指出,那我也实现一个ItemTemplate。请看下图:

 < D​​ataTemplate中X:关键=ListBoxItemVmTemplate>
    <电网的DataContext ={结合}>
        < StackPanel的方向=横向>
            < BORDER X:名称=UpperListBoxTemplateBorder
                    身高=42
                    宽度=44
                    BorderBrush =白
                    了borderThickness =2.5
                    CornerRadius =100
                    保证金=10,16,0,0
                    VerticalAlignment =热门>
                <路径X:名称=DataTemplatePath
                      身高=16
                      宽度=11
                      填写=白
                      拉伸=填充
                      保证金=4,0,0,0
                      的Horizo​​ntalAlignment =中心
                      VerticalAlignment =中心
                      UseLayoutRounding =假
                      数据=M337.59924,129.61948 L337.59924,141.51501 L345.5704,135.87381 Z/>
            < /边框>
            <电网>
                < Grid.RowDefinitions>
                    < RowDefinition高度=40>< / RowDefinition>
                    < RowDefinition高度=22>< / RowDefinition>
                < /Grid.RowDefinitions>
                < StackPanel的方向=横向
                            Grid.Row =0>
                    <控制:EllipsisTextBlock文本={结合DataModel.Title}
                                                =了maxWidth410
                                                保证金=18 12 0 0/>
                < / StackPanel的>
                < StackPanel的方向=横向
                            Grid.Row =1>
                    <控制:EllipsisTextBlock文本={结合DataModel.Street}
                                                字号=16
                                                =了maxWidth410
                                                保证金=18 -3 0 0/>
                    <控制:EllipsisTextBlock文本={结合DataModel.Zip code}
                                                字号=16
                                                =了maxWidth410
                                                保证金=18 -3 0 0/>
                    <控制:EllipsisTextBlock文本={结合DataModel.City}
                                                字号=16
                                                =了maxWidth410
                                                保证金=18 -3 0 0/>
                < / StackPanel的>
            < /网格>
        < / StackPanel的>
    < /网格>
< / DataTemplate中>
 

解决方案

有一个关于检测时,名单上的最后一个项目是滚动查看时的http://blog.slim$c$c.com/2010/09/11/detect-when-a-listbox-scrolls-to-its-end-wp7/

列表框绑定列查找指定内容并选中

您可以使用这种技术来您的按钮,动态地添加到屏幕? 如果需要,你可以再次删除它时,列表滚动。

只是一个想法。

I have the following construct, which shows a DataBound ListBox and a Button inside a StackPanel, which again is placed inside a ScrollViewer:

    <ScrollViewer VerticalScrollBarVisibility="Visible"
                  Height="400">
        <StackPanel Orientation="Vertical"
                    MaxHeight="400">
            <ListBox x:Name="LbTelEntries"
                     SelectionChanged="LbTelEntries_SelectionChanged"
                     MaxHeight="340"
                     VerticalAlignment="Top"
                     ItemsSource="{Binding Path=TelItems}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Templates:ListBoxItemTemplateSelector Content="{Binding}" />
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            <Button x:Name="BtMoreTelEntries"
                    Content="More Results"
                    Click="BtMoreTelEntries_Click"
                    Visibility="{Binding Path=NumberRemainingResults, Converter={StaticResource NullToVisConverter}}"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Bottom"
                    Height="70"
                    Width="410"
                    Margin="0 0 0 0"
                    ></Button>
        </StackPanel>
    </ScrollViewer>

My problem is, that the Button should only appear, when the ListBox is scrolled to the end. Once the Button is clicked, the content of the ListBox is exchanged and the Button should again move to the end of the ListBox...

How would I accomplish this?

EDIT: I should mention, that I am also implementing an ItemTemplate. See below:

<DataTemplate x:Key="ListBoxItemVmTemplate">
    <Grid DataContext="{Binding}">
        <StackPanel Orientation="Horizontal">
            <Border x:Name="UpperListBoxTemplateBorder"
                    Height="42"
                    Width="44"
                    BorderBrush="White"
                    BorderThickness="2.5"
                    CornerRadius="100"
                    Margin="10,16,0,0"
                    VerticalAlignment="Top">
                <Path x:Name="DataTemplatePath"
                      Height="16"
                      Width="11"
                      Fill="White"
                      Stretch="Fill"
                      Margin="4,0,0,0"
                      HorizontalAlignment="Center"
                      VerticalAlignment="Center"
                      UseLayoutRounding="False"
                      Data="M337.59924,129.61948 L337.59924,141.51501 L345.5704,135.87381 z" />
            </Border>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="40"></RowDefinition>
                    <RowDefinition Height="22"></RowDefinition>
                </Grid.RowDefinitions>
                <StackPanel Orientation="Horizontal"
                            Grid.Row="0">
                    <Controls:EllipsisTextBlock Text="{Binding DataModel.Title}"
                                                MaxWidth="410"
                                                Margin="18 12 0 0" />
                </StackPanel>
                <StackPanel Orientation="Horizontal"
                            Grid.Row="1">
                    <Controls:EllipsisTextBlock Text="{Binding DataModel.Street}"
                                                FontSize="16"
                                                MaxWidth="410"
                                                Margin="18 -3 0 0" />
                    <Controls:EllipsisTextBlock Text="{Binding DataModel.ZipCode}"
                                                FontSize="16"
                                                MaxWidth="410"
                                                Margin="18 -3 0 0" />
                    <Controls:EllipsisTextBlock Text="{Binding DataModel.City}"
                                                FontSize="16"
                                                MaxWidth="410"
                                                Margin="18 -3 0 0" />
                </StackPanel>
            </Grid>
        </StackPanel>
    </Grid>
</DataTemplate>

解决方案

There is a blog post about detecting when the last item on a list is scrolled in to view at http://blog.slimcode.com/2010/09/11/detect-when-a-listbox-scrolls-to-its-end-wp7/

Could you use this technique to dynamically add your button to the screen? If needed, you could remove it again when the list is scrolled.

Just a thought.

 
精彩推荐
图片推荐