自定义依赖属性无法识别?

saybookcat 2017-10-30 01:36:45
自定义了ItemsSource SelectedItems两个属性

public static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register("ItemsSource", typeof(ObservableCollection<MultiComboBoxModel>), typeof(MulitComboBoxUserControl),new UIPropertyMetadata(null));


public ObservableCollection<MultiComboBoxModel> ItemsSource
{
get { return (ObservableCollection<MultiComboBoxModel>)GetValue(ItemsSourceProperty); }
set
{
SetValue(ItemsSourceProperty, value);
}
}

public static readonly DependencyProperty SelectedItemsProperty = DependencyProperty.Register("SelectedItems", typeof(ObservableCollection<MultiComboBoxModel>), typeof(MulitComboBoxUserControl), new PropertyMetadata(null,null));

public ObservableCollection<MultiComboBoxModel> SelectedItems
{
get { return (ObservableCollection<MultiComboBoxModel>)GetValue(SelectedItemsProperty); }
set
{
SetValue(SelectedItemsProperty, value);
}
}

用户控件定义

<Grid>
<ComboBox Text="{Binding SelectedText}" IsEditable="True" ItemsSource="{Binding ItemsSource}" >
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsChecked}" Click="CheckBox_Click"/>
<TextBlock Text="{Binding Title}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>

引用时提示ItemsSource SelectedItems无法识别或被访问,是什么情况?

<control:MulitComboBoxUserControl Grid.Row="0" ItemsSource="{Binding ItemsSource}" SelectedItems="{Binding SelectedItems}"></control:MulitComboBoxUserControl>

...全文
670 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
盐希瓶 2021-01-05
  • 打赏
  • 举报
回复
重新生成一下项目
p89787259 2017-11-01
  • 打赏
  • 举报
回复
<ComboBox Text="{Binding SelectedText}" IsEditable="True" ItemsSource="{Binding ItemsSource}" > 你这个地方的绑定有问题吧 ItemsSource="{Binding ElementName=UserControl, Path=ItemsSource}" DataContext="{Binding ElementName=UserControl, Path=DataContext}"
exception92 2017-10-30
  • 打赏
  • 举报
回复
MulitComboBoxUserControl 后台代码贴完整

8,735

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧