自定义控件中的集合不更新视图wpf

自定义控件中的集合不更新视图wpf,wpf,custom-controls,Wpf,Custom Controls,有customcontrol经验的人能帮忙吗 你能发现为什么我的收藏没有更新吗 基本上我有两个列表框,当我在这两个列表框之间移动项目时 项目的计数不会下降。(属性不更新) 调试自定义控件控件控件内的属性正确, 但是,当它传播到使用自定义控件的视图时,它不会 链接,您可以在其中下载项目 我是如此接近,但却如此遥远。 我不想发布大量代码,却没有得到回复。 这个项目很小 我已尝试设置默认绑定,但不起作用 建议 CustomControl(两个列表框和按钮用于左右移动项目) generic.xaml

有customcontrol经验的人能帮忙吗

你能发现为什么我的收藏没有更新吗

基本上我有两个列表框,当我在这两个列表框之间移动项目时 项目的计数不会下降。(属性不更新)

调试自定义控件控件控件内的属性正确, 但是,当它传播到使用自定义控件的视图时,它不会

链接,您可以在其中下载项目

我是如此接近,但却如此遥远。 我不想发布大量代码,却没有得到回复。 这个项目很小

我已尝试设置默认绑定,但不起作用

建议

CustomControl(两个列表框和按钮用于左右移动项目)

generic.xaml

    <ListBox Name="PART_lstLeft" 
          MinHeight="200"
          SelectionMode="Extended"
          ItemsSource="{Binding LeftItems, 
                            RelativeSource={RelativeSource TemplatedParent},
                            Mode=TwoWay}"
          IsSynchronizedWithCurrentItem="True"
          SelectedIndex="0" />

     same for the right listbox
    private ObservableCollection<CustomerViewModel> availableCustomers;
    public ObservableCollection<CustomerViewModel> AvailableCustomers
    {
        get { return availableCustomers; }
        set
        {
            availableCustomers = value;
            OnPropertyChanged("AvailableCustomers");
        }
    }

    private ObservableCollection<CustomerViewModel> selectedCustomers;
    public ObservableCollection<CustomerViewModel> SelectedCustomers
    {
        get { return selectedCustomers; }
        set
        {
            selectedCustomers = value;
            OnPropertyChanged("SelectedCustomers");
        }
    }

右列表框也一样
--xaml的结尾

    <ListBox Name="PART_lstLeft" 
          MinHeight="200"
          SelectionMode="Extended"
          ItemsSource="{Binding LeftItems, 
                            RelativeSource={RelativeSource TemplatedParent},
                            Mode=TwoWay}"
          IsSynchronizedWithCurrentItem="True"
          SelectedIndex="0" />

     same for the right listbox
    private ObservableCollection<CustomerViewModel> availableCustomers;
    public ObservableCollection<CustomerViewModel> AvailableCustomers
    {
        get { return availableCustomers; }
        set
        {
            availableCustomers = value;
            OnPropertyChanged("AvailableCustomers");
        }
    }

    private ObservableCollection<CustomerViewModel> selectedCustomers;
    public ObservableCollection<CustomerViewModel> SelectedCustomers
    {
        get { return selectedCustomers; }
        set
        {
            selectedCustomers = value;
            OnPropertyChanged("SelectedCustomers");
        }
    }
客户控制代码

    public MultipleListControl()
    {
        LeftItems = new ObservableCollection<object>();
        RightItems = new ObservableCollection<object>();
    }

    public static readonly DependencyProperty LeftItemsProperty =
                DependencyProperty.Register("LeftItems",
                    typeof(IEnumerable<object>),
                    typeof(MultipleListControl), new UIPropertyMetadata(null));

    public IEnumerable<object> LeftItems
    {
            get { return (IEnumerable<object>)GetValue(LeftItemsProperty); }
            set { SetValue(LeftItemsProperty, value); }
    }


      public static readonly DependencyProperty RightItemsProperty =
               DependencyProperty.Register("RightItems",
           typeof(IEnumerable<object>),
           typeof(MultipleListControl), new UIPropertyMetadata(null));

    public IEnumerable<object> RightItems
    {
        get { return (IEnumerable<object>)GetValue(RightItemsProperty); }
        set { SetValue(RightItemsProperty, value); }
    }

    etc.... rest irrelevant
public MultipleListControl()
{
LeftItems=新的ObservableCollection();
RightItems=新的ObservableCollection();
}
公共静态只读从属属性LeftItemsProperty=
DependencyProperty.Register(“LeftItems”,
类型(IEnumerable),
typeof(MultipleListControl),新的UIPropertyMetadata(null);
公共IEnumerable LeftItems
{
get{return(IEnumerable)GetValue(LeftItemsProperty);}
set{SetValue(LeftItemsProperty,value);}
}
公共静态只读从属属性RightItemsProperty=
DependencyProperty.Register(“RightItems”,
类型(IEnumerable),
typeof(MultipleListControl),新的UIPropertyMetadata(null);
公共IEnumerableRightItems
{
get{return(IEnumerable)GetValue(RightItemsProperty);}
set{SetValue(RightItemsProperty,value);}
}
等无关紧要
视图模型

    <ListBox Name="PART_lstLeft" 
          MinHeight="200"
          SelectionMode="Extended"
          ItemsSource="{Binding LeftItems, 
                            RelativeSource={RelativeSource TemplatedParent},
                            Mode=TwoWay}"
          IsSynchronizedWithCurrentItem="True"
          SelectedIndex="0" />

     same for the right listbox
    private ObservableCollection<CustomerViewModel> availableCustomers;
    public ObservableCollection<CustomerViewModel> AvailableCustomers
    {
        get { return availableCustomers; }
        set
        {
            availableCustomers = value;
            OnPropertyChanged("AvailableCustomers");
        }
    }

    private ObservableCollection<CustomerViewModel> selectedCustomers;
    public ObservableCollection<CustomerViewModel> SelectedCustomers
    {
        get { return selectedCustomers; }
        set
        {
            selectedCustomers = value;
            OnPropertyChanged("SelectedCustomers");
        }
    }
private-observeCollection-availableCustomers;
公众可观察到的收集可用
{
获取{return availableCustomers;}
设置
{
availableCustomers=值;
房地产变更(“可用客户”);
}
}
私人可观察收集选定客户;
公共可观察收集选定客户
{
获取{返回selectedCustomers;}
设置
{
选定客户=价值;
OnPropertyChanged(“选定客户”);
}
}
查看

  <Window.Resources>
    <viewModels:CustomerSelectorViewModel x:Key="ViewModel" />
  </Window.Resources>        

         <multipleList:MultipleListControl  
                    Name="MultipleListControl1" 
                   LeftItems="{Binding Source=
                   {StaticResource ViewModel},
                   Path=AvailableCustomers,Mode=TwoWay}"

                   RightItems="{Binding Source={StaticResource ViewModel},
                   Path=SelectedCustomers,Mode=TwoWay}" />

首先打开列表框
ItemsSource=“{TemplateBinding LeftItems,

第二个视图;
LeftItems=“{Binding AvailableCustomers
如果在datacontext中设置了viewmodel

应该看看另一个代码,因为您似乎做得不对
以及使用它的解决方案

感谢您的时间,如果您能抽出几分钟来澄清这一点,我将不胜感激,因为它已经困扰了我一段时间。我正在阅读有关自定义控件ETC的内容。但在此期间,我需要整理这一个。项目已绑定,但集合未更新。您进行了更改,但仍然不起作用,col选择没有更新。有什么想法吗?ViewModel是如何定义的?为什么是静态的??LeftItems=“{Binding Source={StaticResource ViewModel???它是LeftItems=“{Binding Source={StaticResource ViewModel}”,Path=AvailableCustomers,Mode=TwoWay}“撤消视图更改;看起来还可以;运行visual的“输出”选项卡时是否有任何绑定错误?