我有UserControl ImageView,我想添加一个名为UseOverlay的cutom属性。在初始化时未设置自定义依赖项属性
<XAML>
<UserControl x:Class="ImageView" .../>
<XAML.cs>
public partial class ImageView : UserControl
{
public static DependencyProperty UseOverlayProperty;
public ImageView()
{
InitializeComponent();
if (UseOverlay)
{
AddOverlay();
}
}
static ImageView()
{
UseOverlayProperty = DependencyProperty.Register("UseOverlay", typeof(bool), typeof(ImageView), new PropertyMetadata(false));
}
public bool UseOverlay
{
get { return (bool)GetValue(UseOverlayProperty); }
set { SetValue(UseOverlayProperty, value); }
}
}
但是,从其他userControl使用时,未设置该属性。将显示ImageView,但没有覆盖,并且调试将UseOverlay显示为false。
<ImageView MaxWidth="450" UseOverlay="True"/>
我错过了什么?
你检查你的输出窗口任何错误消息? –
你没有错误或警告与此问题有关 – lewi