我正在尝试覆盖RadDataFilter ControlTemplates,并使用了自定义用户控件。我的班级中有 2 个依赖项属性:
public static readonly DependencyProperty SelectedItemProperty =
DependencyProperty.Register("SelectedItem", typeof(object), typeof(CustomControl), new UIPropertyMetadata());
public object SelectedItem
{
get { return (object)GetValue(SelectedItemProperty); }
set { SetValue(SelectedItemProperty, value); }
}
public static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register("ItemsSource"
, typeof(IEnumerable)
, typeof(CustomControl));
//, new PropertyMetadata(RadDataFilter.OnItemsSourcePropertyChanged));
public IEnumerable ItemsSource
{
get
{
return this.GetValue(ItemsSourceProperty) as IEnumerable;
}
set
{
this.SetValue(ItemsSourceProperty, value);
}
}
在我的 XAML 中:
<UserControl x:Class="RADDataFilterExample.CustomControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" >
<StackPanel Orientation="Horizontal">
<Button Content="Shankar" Click="Button_Click" />
</StackPanel>
</UserControl>
我使用这个控件的地方在这里:
<local:CustomControl x:Name="PART_SimpleFilterMemberComboBox" Content="Finally!!"
Margin="0,0,3,0" MinWidth="100" VerticalAlignment="Center"
ItemsSource="{Binding SimpleFilter.AvailableMembers}"
SelectedItem="{Binding SimpleFilter.SelectedMember, Mode=TwoWay}" />
其中 SimpleFilter.AvailableMembers 和 SimpleFilter.SelectedMember 是 Telerik 源代码的一部分。
现在我的问题是,如何从我的 CustomControl 中设置 SelectedItem 属性?
请告诉我。