本帖最后由 qq542369628 于 2013-01-11 14:42:15 编辑

解决方案 »

  1.   

    这两个方法作为公用的,每个按钮的mouse Enter、mouse Leave都用这2个方法。
    在方法中 (sender as button).Background = xxx;
      

  2.   

    (sender as Button).Background = new SolidColorBrush(Colors.Red);编译通过,但是运行会出错
      

  3.   

    <Style TargetType="{x:Type Button}" x:Key="ToolBarBtn">
                    <Setter Property="Background" Value="#FFE2E2E2"/>
                    <Setter Property="BorderBrush" Value="#20000000"/>
                    <Setter Property="MinWidth" Value="90"/>
                    <Setter Property="Cursor" Value="Hand"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type Button}">
                                <Border x:Name="Back" CornerRadius="3" BorderThickness="1" 
                                                    Background="{TemplateBinding Background}" 
                                                    BorderBrush="{TemplateBinding BorderBrush}">
                                    <Grid>
                                        <ContentPresenter Margin="2"  HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                    </Grid>                            </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter Property="Background" Value="#FFC2E0FF"/>
                                        <Setter Property="BorderBrush" Value="#FF3399FF"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
    把style加到页面的resource里面 所以button都变