Enum遍历

  1. private void Window_Loaded(object sender, RoutedEventArgs e)
  2. {
  3. foreach (InkCanvasEditingMode mode in Enum.GetValues(typeof(InkCanvasEditingMode)))
  4. {
  5. this.Editermod.Items.Add(mode);
  6. }
  7. Editermod.SelectedIndex = 0;
  8. }
  9. private void Editermod_SelectionChanged(object sender, SelectionChangedEventArgs e)
  10. {
  11. InkCanvas1.EditingMode = (InkCanvasEditingMode)Editermod.SelectedItem;
  12. }
  1. <Grid>
  2. <Grid.RowDefinitions>
  3. <RowDefinition Height="35"></RowDefinition>
  4. <RowDefinition></RowDefinition>
  5. </Grid.RowDefinitions>
  6. <StackPanel>
  7. <ComboBox Name="Editermod" Margin="5" Panel.ZIndex="23" SelectionChanged="Editermod_SelectionChanged"></ComboBox>
  8. </StackPanel>
  9. <InkCanvas EditingMode="None" Grid.Row="1" Name="InkCanvas1" Background="#FFF7C6C6">
  10. <Button InkCanvas.Right="20" InkCanvas.Bottom="10" Content="清空" Padding="10,2" Click="Button_Click"/>
  11. </InkCanvas>
  12. </Grid>

Enum遍历 - 图1