依赖属性和TypeInitializationException

时间:2013-05-23 18:30:51

标签: c# .net silverlight windows-phone-7 windows-phone-8

我有一个奇怪的问题,我不知道到底发生了什么。在我的Windows Phone 8应用程序中,我使用依赖属性创建了用户控件:

public string Symbol
    {
        get { return (string)GetValue(SymbolProperty); }
        set { SetValue(SymbolProperty, value); }
    }

    public static readonly DependencyProperty SymbolProperty = DependencyProperty.Register(
        "Symbol", typeof(string), typeof(SymbolControl), new PropertyMetadata(""));


    public SymbolControl()
    {
        InitializeComponent();

    }

用户控制视图:

<Grid x:Name="SymbolRoot" Background="DarkBlue">
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="2*"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <TextBox Text="{Binding Symbol}" Grid.Row="1" Background="Azure" />
</Grid>

现在在我的应用程序视图中我创建了

<customControls:SymbolControl Symbol="test" />

应用程序总是从符号的setter抛出TypeInitializationException。我无法在代码中找到该错误的解决方案。有人能帮我吗 ?

堆栈追踪:

  

在System.Windows.DependencyProperty.Register(Boolean fIsAttachedDP,   字符串名称,类型propertyType,类型ownerType,PropertyMetadata   propertyMetadata,Boolean readOnly)at   System.Windows.DependencyProperty.Register(String name,Type   propertyType,Type ownerType,PropertyMetadata typeMetadata)at   Application.WP8.Controls.Symbol.SymbolControl..cctor()

0 个答案:

没有答案
相关问题