我的用戶控件有以下DP:如何通過樣式設置器設置DepedencyProperty?
public static readonly DependencyProperty ButtonAnimationColorProperty =
DependencyProperty.Register("ButtonAnimationColor", typeof(Color), typeof(MyControl),
new FrameworkPropertyMetadata(Colors.RoyalBlue, FrameworkPropertyMetadataOptions.AffectsRender, ThemeUpdate));
public Color ButtonAnimationColor
{
get { return (Color)GetValue(ButtonAnimationColorProperty); }
set { SetValue(ButtonAnimationColorProperty , value); }
}
這種控制被編譯成一個DLL,我在其他解決方案中使用。它完美的作品很好,當我直接設置:
<ns:MyControl>
<ns:MyControl.Style>
<Style>
<Setter Property="ButtonAnimationColor" Value="Green" />
</Style>
</ns:MyControl.Style>
</ns:MyControl>
它給我以下錯誤:
<ns:MyControl ButtonAnimationColor="Green" />
,當我試圖通過使用樣式二傳手設置這個DP一樣,發生的問題
成員「ButtoAnimationColor」無法識別或不可訪問。
我需要在代碼中進行哪些更改才能設置屬性?
拼寫是否正確呢?你的錯誤是'ButtonnimationColor'。 – gleng
對不起,考慮一下代碼。我會更新這個問題。 – Guilherme