, ComboBox , ?
, , combobox, wpf
, , combobox - ItemsSource. , , "", , ItemsSource :
<ComboBox ItemsSource="{StaticResource stringList}" />
:
public class StringList : List<string> { }
<Window.Resources>
<local:StringList x:Key="stringList">
<sys:String>Monday</sys:String>
<sys:String>Wednesday</sys:String>
<sys:String>Friday</sys:String>
</local:StringList >
</Window.Resources>
, .
: DependencyProperty StringList String [], .
<local:MyComboBox MyProperty="{StaticResource stringList}" Height="23" />
dependencyProperty:
public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.Register("MyProperty",typeof(StringList),typeof(MyComboBox),new FrameworkPropertyMetadata(null, listChangedCallBack));
static void listChangedCallBack(DependencyObject property, DependencyPropertyChangedEventArgs args)
{
ComboBox combo = (ComboBox)property;
combo.ItemsSource= (IEnumerable)args.NewValue;
}
, ItemsSource. , , Dependency .