MSDN > 論壇首頁 > Visual Studio WPF Designer > Compile-time conundrum
發問發問
 

已答覆Compile-time conundrum

  • Tuesday, 23 June, 2009 20:25B. Clay Shannon 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    I asked this over in the WPF General forum and was advised to move it here (nobody could see what was wrong this code, I guess).

    'm trying to add a style to my App.xaml file, which looks like this:

    <Application x:Class="WPFShowcaseApp.App"
        xmlns="
    http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="
    http://schemas.microsoft.com/winfx/2006/xaml"
        StartupUri="Window1.xaml">
        <Application.Resources>
            <Style x:Key="WackyButtonStyle" TargetType="{x:Type Button}">     
                <Setter Property="Height" Value="200" />      
                <Setter Property="Width" Value="75" />      
                <Setter Property="VerticalAlignment" Value="Top" />      
                <Setter Property="FontSize" Value="11pt" />    
            </Style>
        </Application.Resources>
    </Application>

    ..but I'm getting a slew of err msgs. The first one is: "The Element type 'System.Windows.Style' does not have an associated TypeConverter to parse the string '"

    ...and then there's a ton like this: "A value of type 'String' cannot be added to a collection or dictionary of type 'SetterBaseCollection'."

    What am I missing here (conceptually or literally)?


    Delphi ancient/C# newbie

解答

  • Tuesday, 30 June, 2009 1:03Mark Wilson-ThomasMSFT, 版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
    I cannot see anything wrong with this code, Clay.

    I've tried adding it to a fresh WPF project's app.xaml in VS2008 SP1, and it gave me no errors and compiled just fine.

    I even tried applying the style to a few buttons in a window1.xaml file and saw the anticipated results

    <Button Style="{StaticResource ResourceKey=WackyButtonStyle}" >StyledButton</Button>



    I think there must be some other problem at work in your project or your installation.

    If you create a brand-new WPF project on your machine, and paste the Application.Resources block above into your app.xaml, do the same issues apply?

    Mark

     

     


    Mark Wilson-Thomas - Program Team - WPF & SL Designer for Visual Studio - posts are provided 'as-is'

所有回覆

  • Tuesday, 30 June, 2009 1:03Mark Wilson-ThomasMSFT, 版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
    I cannot see anything wrong with this code, Clay.

    I've tried adding it to a fresh WPF project's app.xaml in VS2008 SP1, and it gave me no errors and compiled just fine.

    I even tried applying the style to a few buttons in a window1.xaml file and saw the anticipated results

    <Button Style="{StaticResource ResourceKey=WackyButtonStyle}" >StyledButton</Button>



    I think there must be some other problem at work in your project or your installation.

    If you create a brand-new WPF project on your machine, and paste the Application.Resources block above into your app.xaml, do the same issues apply?

    Mark

     

     


    Mark Wilson-Thomas - Program Team - WPF & SL Designer for Visual Studio - posts are provided 'as-is'
  • Tuesday, 30 June, 2009 14:29B. Clay Shannon 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Thanks; I added it to a new project, and there was no problem. I guess "Gremlins" infested the other one.
    Delphi ancient/C# newbie