WPF模板错误 – “提供价值在’System.Windows.Baml2006.TypeConverterMarkupExtension’抛出一个异常.

前端之家收集整理的这篇文章主要介绍了WPF模板错误 – “提供价值在’System.Windows.Baml2006.TypeConverterMarkupExtension’抛出一个异常.前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我刚刚开始尝试使用WPF模板与样式,我不知道我做错了什么.下面的目标是在菜单中替换选项的颜色.代码工作正常,但是当我复制并粘贴/重命名为“MenuChoiceOdd”的第二段时,我得到以下错误

>在“System.Windows.Baml2006.TypeConverterMarkupExtension”上提供值提出异常.

代码示例:

<Window x:Class="WpfApplication1.Template_Testing"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Template_Testing" Height="300" Width="300">
    <Grid>
        <Grid.Resources>
            <ControlTemplate x:Key="MenuChoiceEven">
                <Border BorderThickness="1" BorderBrush="#FF4A5D80">
                <TextBlock Height="Auto" HorizontalAlignment="Stretch" Margin="0"  Width="Auto" FontSize="14" Foreground="SlateGray" TextAlignment="Left" AllowDrop="True" Text="{Binding Path=Content,RelativeSource={RelativeSource TemplatedParent}}">
                    <TextBlock.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="White" Offset="0" />
                            <GradientStop Color="#FFC2CCDB" Offset="1" />
                        </LinearGradientBrush>
                    </TextBlock.Background>
                </TextBlock>
                </Border>
            </ControlTemplate>
            <ControlTemplate x:Key="MenuChoiceOdd">
                <Border BorderThickness="1" BorderBrush="#FF4A5D80">
                    <TextBlock Height="Auto" HorizontalAlignment="Stretch" Margin="0"  Width="Auto" FontSize="14" Foreground="SlateGray" TextAlignment="Left" AllowDrop="True" Text="{Binding Path=Content,0">
                            <GradientStop Color="White" Offset="0" />
                            <GradientStop Color="##FFCBCBCB" Offset="1" />
                        </LinearGradientBrush>
                    </TextBlock.Background>
                    </TextBlock>
                </Border>
            </ControlTemplate>            
        </Grid.Resources>
        <Border BorderBrush="SlateGray" BorderThickness="2" Margin="10" CornerRadius="10" Background="LightSteelBlue" Width="200">
            <StackPanel Margin="4">
                <TextBlock Height="Auto" HorizontalAlignment="Stretch" Margin="2,2,0" Name="MenuHeaderTextBlock" Text="TextBlock" Width="Auto" FontSize="16" Foreground="PaleGoldenrod" TextAlignment="Left" Padding="10" FontWeight="Bold"><TextBlock.Background><LinearGradientBrush EndPoint="0.5,0"><GradientStop Color="LightSlateGray" Offset="0" /><GradientStop Color="DarkSlateGray" Offset="1" /></LinearGradientBrush></TextBlock.Background></TextBlock>
                <StackPanel Height="Auto" HorizontalAlignment="Stretch" Margin="2,0" Name="MenuChoicesStackPanel" VerticalAlignment="Top" Width="Auto">
                    <Button Template="{StaticResource MenuChoiceEven}" Content="Test Even menu element" />
                    <Button Template="{StaticResource MenuChoiceOdd}"  Content="Test odd menu element" />
                </StackPanel>
            </StackPanel>
        </Border>
    </Grid>
</Window>

我究竟做错了什么?

这是星期一吗

当我从另一个控件复制粘贴颜色字符串时,在前缀中添加两个“##”:

<GradientStop Color="##FFCBCBCB" Offset="1" />

仍然是一个糟糕的错误信息.

猜你在找的Windows相关文章