遍历集合下的按钮

来源:互联网 发布:金蝶k3软件下载 编辑:程序博客网 时间:2024/05/18 01:34

 private void btn_Click(object sender, RoutedEventArgs e)
        {
            FrameworkElement feSource = e.Source as FrameworkElement;
            switch (feSource.Name)
            {
                case "btn_Blue":
                    btn_Yellow.Content = "Yellow";
                    btn_Red.Content = "Red";
                    btn_Blue.Content = "Hello Blue!";
                    break;
                case "btn_Yellow":
                    btn_Red.Content = "Red";
                    btn_Blue.Content = "Blue";
                    btn_Yellow.Content = "Hello Yellow!";
                    break;
                case "btn_Red":
                    btn_Blue.Content = "Blue";
                    btn_Yellow.Content = "Yellow";
                    btn_Red.Content = "Hello Red!";
                    break;
            }
      

  <Border Height="80" Width="350" BorderBrush="Red" BorderThickness="4" >
            <StackPanel Background="LightBlue" Orientation="Horizontal" Button.Click="btn_Click" Margin="10,10,10,10" >
                <Button Background="Blue" Name="btn_Blue" Width="80" Margin="10,10,10,10">Blue</Button>
                <Button Background="Red" Name="btn_Red" Width="80" Margin="10,10,10,10">Red</Button>
                <Button Background="Yellow" Name="btn_Yellow" Width="80" Margin="10,10,10,10">Yellow</Button>
            </StackPanel>
        </Border>