任何有自定义控制经验的人都可以提供帮助吗????
你能发现为什么我的收藏没有更新吗?
基本上我有 2 个列表框,当我在两者之间移动项目时 项目计数不会下降。(属性不会更新)
调试自定义控件 控件中的属性是否正确 , 但是,当它传播到使用自定义控件的视图时,它不会!
链接,您可以在其中下载项目。
https://1drv.ms/f/s!AmyWRgk_dFxGaohoQA_v-aulUOE
我离得那么近,却又那么远。 我不想发布大量代码而没有得到回复。 项目很小。
我尝试默认设置绑定,但不起作用。
建议?
自定义控件(2 个列表框和按钮,用于左右移动项目)
通用.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 的结束
自定义控件代码
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}" />
首先是列表框;ItemsSource="{TemplateBinding LeftItems,
第二你的观点 ;LeftItems="{Binding AvailableCustomers
视图模型是否在数据上下文中设置
应该看看另一个代码,因为看起来你做得不对 定制和使用IT解决方案的解决方案