注:在此回答一个代码块试图重复这个问题:
<UserControl x:Class="SilverlightApplication2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<UserControl.Resources>
<Style x:Key="RadioButtonStyle2"
TargetType="RadioButton">
<Setter Property="Foreground"
Value="#5DFFC8" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RadioButton">
<Grid>
<vsm:VisualStateManager.VisualStateGroups>
<vsm:VisualStateGroup x:Name="CheckStates">
<vsm:VisualState x:Name="Checked">
<Storyboard>
<DoubleAnimation Duration="0"
Storyboard.TargetName="RadioButtonPart"
Storyboard.TargetProperty="Opacity"
To="1" />
<ColorAnimation Duration="0"
Storyboard.TargetName="RadioButtonPart"
Storyboard.TargetProperty="Foreground"
To="Black" />
</Storyboard>
</vsm:VisualState>
</vsm:VisualStateGroup>
</vsm:VisualStateManager.VisualStateGroups>
<RadioButton x:Name="RadioButtonPart" Foreground="{TemplateBinding Foreground}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot"
Background="White">
<RadioButton Style="{StaticResource RadioButtonStyle2}" IsChecked="True">Test</RadioButton>
</Grid>
</UserControl>
如果显示的代码就是一切,有很多缺失。
我粘贴了我用来测试你的风格的代码,并添加了一些。看一看在设计之外,它可能会是这样的:
这应该告诉你什么是错的。在我的代码中,前景属性(Brush)和动画(Color)的类型不匹配。
您将可以使他们通过动画刷的颜色属性(SolidBrush)
下面是一个更好的工作样品不一致(还没有完成,但动画工作)
<UserControl x:Class="SilverlightApplication2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<UserControl.Resources>
<Style x:Key="RadioButtonStyle2"
TargetType="RadioButton">
<Setter Property="Foreground"
Value="#5DFFC8" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RadioButton">
<Grid>
<vsm:VisualStateManager.VisualStateGroups>
<vsm:VisualStateGroup x:Name="CheckStates">
<vsm:VisualState x:Name="Checked">
<Storyboard>
<DoubleAnimation Duration="0"
Storyboard.TargetName="RadioButtonPart"
Storyboard.TargetProperty="Opacity"
To="1" />
<ColorAnimation Duration="0"
Storyboard.TargetName="radioButtonForegroundColor"
Storyboard.TargetProperty="Color"
To="Black" />
</Storyboard>
</vsm:VisualState>
<vsm:VisualState x:Name="Unchecked">
<Storyboard>
<DoubleAnimation Duration="0"
Storyboard.TargetName="RadioButtonPart"
Storyboard.TargetProperty="Opacity"
To="0.5" />
<ColorAnimation Duration="0"
Storyboard.TargetName="radioButtonForegroundColor"
Storyboard.TargetProperty="Color"
To="Red" />
</Storyboard>
</vsm:VisualState>
</vsm:VisualStateGroup>
</vsm:VisualStateManager.VisualStateGroups>
<RadioButton x:Name="RadioButtonPart"
IsChecked="{TemplateBinding IsChecked}"
Content="{TemplateBinding Content}">
<RadioButton.Foreground>
<SolidColorBrush Color="White"
x:Name="radioButtonForegroundColor" />
</RadioButton.Foreground>
</RadioButton>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot"
Background="White">
<StackPanel>
<RadioButton Style="{StaticResource RadioButtonStyle2}"
Content="Test 1" />
<RadioButton Style="{StaticResource RadioButtonStyle2}"
IsChecked="False"
Content="Test 2" />
</StackPanel>
</Grid>
</UserControl>
这只是风格的一部分。发布一切,请尽可能具体:什么崩溃?什么是例外?你确定它是模板吗? –
这是造成坠毁的部分。当我说这部分全部没有崩溃时工作 – Yanshof
当你从你的解决方案中删除这段代码时,它不会编译。请张贴所有样式代码。 –