4

我有这样的事情:

                        <Grid>
                            <StackPanel Margin="100,0,98,0">
                                <Button x:Name="BtProd"
                                   Content="{Binding Produto}"     
                                   FontSize="{StaticResource PhoneFontSizeLarge}"
                                   Foreground="{Binding Color}"
                                   Click="BtProd_Click">
                                </Button>
                            </StackPanel>
                        </Grid>

如何更改 C# .cs 文件中按钮的文本颜色?

   private void BtProd_Click(object sender, RoutedEventArgs e)
    {
    ?
    }

当用户单击按钮时,我想从白色变为浅灰色。谢谢你。

4

2 回答 2

2
(sender as Button).Foreground = new SolidColorBrush(Colors.LightGray);
于 2013-11-07T00:22:33.500 回答
2

您可能需要考虑使用如下样式触发器:

       <Style x:Key="ButtonPressStyle"
               TargetType="Button">
            <Style.Triggers>
                <Trigger Property="IsPressed"
                         Value="True">
                    <Setter Property="Foreground">
                        <Setter.Value>
                            Red
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>

然后你像这样定义你的按钮:

                            <Button x:Name="BtProd"
                               Content="{Binding Produto}"     
                               FontSize="{StaticResource PhoneFontSizeLarge}"
                               Foreground="{Binding Color}"
                               Style="{StaticResource ButtonPressStyle}"
                               Click="BtProd_Click">
                            </Button>
于 2013-11-07T01:21:03.100 回答