天天看點

WPF 綁定枚舉值

原文: WPF 綁定枚舉值 前台Xaml      

<ComboBox x:Name="cmboxStretch"  Width="120" Height="35" HorizontalAlignment="Left" Margin="5 0 0 0"
                             SelectedItem="{Binding Path=Stretch}"
                             VerticalContentAlignment="Center">
            </ComboBox>      
<Viewbox Stretch="{Binding SelectedValue,ElementName=cmboxStretch}" Grid.Row="1" x:Name="viewBox">
  </Viewbox>      

背景代碼     

cmboxStretch.ItemsSource= System.Enum.GetValues(typeof(Stretch));      

選擇Combox就能看到ViewBox屬性值Stretch在變化了。