任何具有一些自定义控制经验的人都可以帮助????
你能发现为什么我的收藏品没有更新吗?
基本上我有2个列表框,当我在两者之间移动项目时 物品的数量不会下降。(物业不会更新)
调试自定义控件,控件中的属性是正确的, 但当它传播到使用自定义控件的视图时,它不会!。
您可以下载项目的链接。
https://1drv.ms/f/s!AmyWRgk_dFxGaohoQA_v-aulUOE
我很亲密,但到目前为止。 我不想发布大量代码并且没有得到回复。 项目很小。
我已尝试默认设置绑定但不起作用。
建议?
CustomControl(左侧和右侧移动项目的2个列表框和按钮)
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
- 结束xaml
CustomControl代码
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
视图模型
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");
}
}
查看
<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}" />