x: 在windows 10模式下单向绑定

本文关键字:绑定 模式 windows | 更新日期: 2023-09-27 18:00:36

当滚动条到达末尾时,我正在尝试更新绑定到ListBox的列表。我需要更新列表并在UI中显示更改。这里它不是自动更新的。有人能帮我完成我的要求吗。

如果我尝试使用双向模式,它显示以下错误:

错误:无效的绑定路径"itemsList":无法在没有转换器的情况下将类型"System.Collections.Generic.List(System.String)"绑定到"System.Object"

 <ScrollViewer
            x:Name="sv"
            ViewChanged="OnScrollViewerViewChanged">
            <ListBox x:Name="listView"
                HorizontalAlignment="Left" 
                Height="Auto" 
                VerticalAlignment="Top" 
                Width="172"
                ItemsSource="{x:Bind itemsList, Mode=OneWay}"/>
 </ScrollViewer>

和代码

     public List<String> itemsList = new List<string>();
     private void OnScrollViewerViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
                {
                    var verticalOffset = sv.VerticalOffset;
                    var maxVerticalOffset = sv.ScrollableHeight; //sv.ExtentHeight - sv.ViewportHeight;
                    if (maxVerticalOffset < 0 ||
                        verticalOffset == maxVerticalOffset)
                    {
                        // Scrolled to bottom
                        Util.debugLog("REACHED BOTTOM");
                        int i;
                        //   itemsList = null;
                        itemsList.Clear();
                        for (i = 0; i < 20; i++)
                        {
                            itemsList.Add("Item number " + i + 900);
                        }
                    }
                    else
                    {
                        // Not scrolled to bottom
                        //   rect.Fill = new SolidColorBrush(Colors.Yellow);
                    }
                }

x: 在windows 10模式下单向绑定

这里(在下面的链接中)是我的问题的答案。非常感谢所有试图回答我问题的人。

https://social.technet.microsoft.com/Forums/en-US/7c730558-f933-4483-8d5b-1710d19f99de/xbind-in-windows-10-mode-one-way-i-am-trying-to-update-the-bind-list-when-scrollview-reached-to?forum=wpf