如果禁用单选按钮,则在Windows Phone 7的单选按钮中首次应用前景色。
这是我的代码 -
RadioButton1.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 100, 0));//Green
RadioButton2.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));//White
RadioButton3.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));
RadioButton4.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));
RadioButton1.IsEnabled = false;
RadioButton1.IsChecked = true;
RadioButton2.IsEnabled = false;
RadioButton3.IsEnabled = false;
RadioButton4.IsEnabled = false;
这是我的xaml
<StackPanel x:Name="panel" Orientation="Vertical" >
<RadioButton x:Name="RadioButton1">
<RadioButton.Content>
<TextBlock Text="" x:Name="RadioButton1Text" TextWrapping="Wrap" />
</RadioButton.Content>
</RadioButton>
<RadioButton x:Name="RadioButton2">
<RadioButton.Content>
<TextBlock Text="" x:Name="RadioButton2Text" TextWrapping="Wrap" />
</RadioButton.Content>
</RadioButton>
<RadioButton x:Name="RadioButton3">
<RadioButton.Content>
<TextBlock Text="" x:Name="RadioButton3Text" TextWrapping="Wrap" />
</RadioButton.Content>
</RadioButton>
<RadioButton x:Name="RadioButton4">
<RadioButton.Content>
<TextBlock Text="" x:Name="RadioButton4Text" TextWrapping="Wrap" />
</RadioButton.Content>
</RadioButton>
</StackPanel>
答案 0 :(得分:1)
RadioButton
的模板在禁用时具有不同的可视状态。在禁用状态之间转换时所做的更改将更新Foreground
属性,从而覆盖您在代码中进行的显式更改。
根据您要实现的目标,您可以为radiobutton创建一种新样式,以改变禁用状态的模板更改,或者您可以通过以不同方式更改ForegroundBrush来指示您尝试指示的任何内容。