项目观察集合的更改显示(UI)/订单订单、项目、UI

2023-09-06 04:52:49 作者:最帅的坏蛋

编辑#2:

 公共无效ReverseOrderRegBtns()
    {
        ICollectionView的观点= CollectionViewSource.GetDefaultView(GlobalObservableCol.regBtns);
        view.SortDescriptions.Add(新SortDescription(ReverseOrder,ListSortDirection.Ascending));
        view.Refresh();
    }
 

不是真的知道如何适应的ICollectionView中,它也中断了正在做一些逻辑定时器。出于某种原因,它interupts我的时间被创建一个按钮时开始计数。

我的应用程序有几个定时器,以便让创建的按钮获取可能的新内容更新每隔x秒金额。的

编辑:

数据绑定看起来如下:

 < ListBox的X:名称=lbRegistration的ItemsSource ={结合regBtnsReverse,的ElementName =窗口}背景={X:空}
 

旧:      公众的ObservableCollection RegBtns             {                 得到                 {                     如果(GlobalObservableCol.regBtns == NULL)                     {                         返回新的ObservableCollection();                     }                     返回GlobalObservableCol.regBtns;                 }             }

UI作品

新(不再工作),相反的是,在ObserableCol类

 公开的IEnumerable< RegistrationButton> RegBtns
        {
            得到
            {
                返回GlobalObservableCol.regBtnsReverse;
            }
        }
 

我在一个静态类,其中的ObservableCollection名单可创建了IEnumerable

我似乎无法约束的时候,我的数据绑定是一个IEnumerable的。如何绑定NumbersReverse  方法位于一个其他类我MainWindow.xls?的

我有保存自定义样式的WPF按钮的的ObservableCollection。

这些项目将动态创建和添加的自定义滑块控件(列表框)。 例如按钮1,按钮2,按钮3,...

我要的是完全的相对

例如按钮3,按钮2,按钮1。的 这听起来像一个链表,但我的整个应用程序已在使用的整个逻辑这个观察的集合。

在按钮得到显示在用户界面的最后添加的按钮要放在我的滑块上的第一个项目(这是一个列表框控件)。

我究竟如何能拉这一关?

谢谢, PeterP

解决方案

 <列表框的ItemsSource ={结合美孚}/>

私人的ObservableCollection< RegButtton> RegBtns =新...;

公众的ICollectionView富{获得;组; }

富= CollectionViewSource.GetDefaultView(RegBtns);
Foo.SortDescriptions.Add(新SortDescription(SomePropertyName,ListSortDirection.Ascending));
Foo.Refresh();
 

EDIT #2:

    public void ReverseOrderRegBtns()
    {
        ICollectionView view = CollectionViewSource.GetDefaultView(GlobalObservableCol.regBtns);
        view.SortDescriptions.Add(new SortDescription("ReverseOrder", ListSortDirection.Ascending));
        view.Refresh();
    }

Not really sure how to fit the ICollectionView in, it also interrupts timers that are doing some logic. For some reason it interupts my timing that starts counting when a button gets created.

My application has several timers, so the buttons that get created get updates with possible new content every x amount of seconds.

EDIT:

The databinding looks as following:

<ListBox x:Name="lbRegistration" ItemsSource="{Binding regBtnsReverse, ElementName=Window}" Background="{x:Null}" 

Old: public ObservableCollection RegBtns { get { if (GlobalObservableCol.regBtns == null) { return new ObservableCollection(); } return GlobalObservableCol.regBtns; } }

New (no longer works), the reverse is in the ObserableCol class

public IEnumerable<RegistrationButton> RegBtns
        {
            get
            {
                return GlobalObservableCol.regBtnsReverse;
            }
        }

I have created the IEnumerable in my a static class where the ObservableCollection list is available.

I cannot seem to bind when my databinding is a IENumerable. How to bind the NumbersReverse method that is located in a other class to my MainWindow.xls?

I have a ObservableCollection that holds custom styled WPF buttons.

Those items get dynamically created and added on a custom slider control (listbox). For example Button 1, Button 2, Button 3, ...

What i want is exactly the opposite.

For example Button 3, Button 2, Button 1. This sounds like a linked list but my entire application is already using this Observable Collection throughout the entire logic.

When the buttons get displayed in the UI the last added button should be placed as the first item on my slider (that is a listbox control).

How exactly can i pull this off?

Thanks, PeterP

解决方案

<ListBox ItemsSource="{Binding Foo}"/>

private ObservableCollection<RegButtton> RegBtns = new...;

public ICollectionView Foo { get; set; }

Foo = CollectionViewSource.GetDefaultView(RegBtns);
Foo.SortDescriptions.Add(new SortDescription("SomePropertyName", ListSortDirection.Ascending));
Foo.Refresh();