0
我有一個用戶控件,它有問題綁定到IsEnabled的依賴項屬性。我也嘗試手動設置IsEnabled =「false」,這也似乎不起作用。不依賴於UserControl的依賴屬性
下面是代碼:
public partial class News : UserControl
{
public static readonly DependencyProperty IsAuthenticatedProperty =
DependencyProperty.Register(
"IsAuthenticated",
typeof(bool),
typeof(News),
new FrameworkPropertyMetadata(
new PropertyChangedCallback(ChangeAuth)));
public bool IsAuthenticated
{
get
{
return (bool) GetValue(IsAuthenticatedProperty);
}
set
{
SetValue(IsAuthenticatedProperty, value);
}
}
private static void ChangeAuth(DependencyObject source, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue is bool == false)
{
(source as News).UpdateAuth(false);
}
else
{
(source as News).UpdateAuth(true);
}
}
private void UpdateAuth(bool value)
{
IsAuthenticated = value;
}
public News()
{
IsAuthenticated = false;
this.IsEnabled = false;
InitializeComponent();
}
什麼想法?提前致謝