您可以通过将以下代码放在Window
Loaded事件处理程序中来从代码中完成操作,例如:
yourComboBox.ItemsSource = Enum.GetValues(typeof(EffectStyle)).Cast<EffectStyle>();
如果需要在XAML中绑定它,则需要使用它
ObjectDataProvider来创建可用作绑定源的对象:
<Window x:Class="YourNamespace.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib" xmlns:StyleAlias="clr-namespace:Motion.VideoEffects"> <Window.Resources> <ObjectDataProvider x:Key="dataFromEnum" MethodName="GetValues" ObjectType="{x:Type System:Enum}"> <ObjectDataProvider.MethodParameters> <x:Type TypeName="StyleAlias:EffectStyle"/> </ObjectDataProvider.MethodParameters> </ObjectDataProvider> </Window.Resources> <Grid> <ComboBox ItemsSource="{Binding Source={StaticResource dataFromEnum}}" SelectedItem="{Binding Path=CurrentEffectStyle}" /> </Grid></Window>在下一个代码上引起注意:
xmlns:System="clr-namespace:System;assembly=mscorlib"xmlns:StyleAlias="clr-namespace:Motion.VideoEffects"
指导如何映射可在MSDN上阅读的名称空间和程序集。



