2016-03-28 6 views
3

私はカスタムコントロールLineChartを持っています。 xaml.csでコード:他のページでUWPカスタムコントロールのプロパティエラーに割り当てられませんでした

public Brush Abc 
{ 
    get { return new SolidColorBrush(new Color() {A = 123, B = 123, G = 23, R = 12 }); } 
} 

<controls:LineChart Stroke="{Binding Abc}" /> 

すべてのコードStroke="Green"の静的行と正常に動作しますが、私は使用してビューモデルクラスで

public static readonly DependencyProperty StrokeProperty = 
     DependencyProperty.Register("StrokeProperty", typeof(Brush), typeof(LineChart), new PropertyMetadata(new SolidColorBrush(), 
      new PropertyChangedCallback(OnItemsChanged))); 

public Brush Stroke 
{ 
    get { return (Brush)GetValue(StrokeProperty); } 
    set { SetValue(StrokeProperty, value); } 
} 

Binding、プログラムがエラーで破損しました:

Windows.UI.Xaml.Markup.XamlParseException: The text associated with this error code could not be found.

Failed to assign to property CurrencyExchangeUniversal.App.Controls.LineChart.Stroke'. [Line: 102 Position: 41] at Windows.UI.Xaml.Application.LoadComponent(Object component, Uri resourceLocator, ComponentResourceLocation componentResourceLocation) at CurrencyExchangeUniversal.App.View.NationalBankPage.InitializeComponent() at CurrencyExchangeUniversal.App.View.NationalBankPage..ctor()

+0

Abcのの種類は何ですか:最初の引数の値が"Stroke"、ない"StrokeProperty"すべきですか? – Archana

+0

'Abc'のコードを追加しました –

+0

Bindingのようですね。 OnItemsChangedメソッドのチェック – Archana

答えて

3

DependencyProperty.Registerコールで間違いをしました。

public static readonly DependencyProperty StrokeProperty = 
     DependencyProperty.Register("Stroke", typeof(Brush), typeof(LineChart), new PropertyMetadata(new SolidColorBrush(), 
      new PropertyChangedCallback(OnItemsChanged))); 
+0

StackOverflowの1つの問題は、私にはあまりにも頻繁に起こります。私は質問者と同じ間違いを犯さなかったし、私はまだ同じ問題があります。この質問は「返信」されているので、私は今解決策を見つけるようには思われません。 –

関連する問題