无法解析资源“XX”

时间:2013-12-08 03:30:52

标签: c# xaml xaml-resources

运行程序时出现以下错误:

  

警告无法解析资源“bellRingersStyle”。

最后两行为{StaticResource bellRingersStyle}

    <Window x:Class="BellRingers.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Middleshire Bell Ringers Association – Members" Height="350" Width="525">
    <Window.Resources>
        <Style x:Key="bellRingerStyle" TargetType="Control">
            <Setter Property="Button.Background" Value="Gray"/>
            <Setter Property="Button.Foreground" Value="Gray"/>
            <Setter Property="Button.FontFamily" Value="Comic Sans MS"/>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="Blue"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Grid>
        <Button Style="{StaticResource bellRingerStyle}" Panel.ZIndex="1" Content="Button" Height="23" HorizontalAlignment="Left" Margin="400,131,0,0" Name="button1" VerticalAlignment="Top" Width="75" >
            </Button>
        <Button Style="{StaticResource bellRingersStyle}" Panel.ZIndex="1" Content="Button" Height="23" Margin="0,0,0,0" Name="button2" Width="75" />
            <Image Panel.ZIndex="0" Margin="0,0,0,0" Name="image1" >
            <Image.Source>
                <BitmapImage UriSource="bell.gif" />
            </Image.Source>
        </Image>
        <TextBox Style="{StaticResource bellRingersStyle}"  Height="23" HorizontalAlignment="Left" Margin="206,271,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" />
    </Grid>
</Window>

1 个答案:

答案 0 :(得分:2)

你有一个错字。您将其定义为bellRingerStyle,但引用了bellRingersStyle。