我有一个需要从 GridView 继承的自定义控件。和标准方式,适用于 UserControl,
<UserControl.Resources>
<local:NodeToImageConverter x:Key="imageConverter" />
<local:ImageHeightConverter x:Key="imageHeightConverter" />
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)
它对我不起作用。我真的很想使用本地资源——而不是把它们放在更高的位置。我试图创建一个级别的类并为那里的资源声明一个依赖属性。但它没有用:
public partial class CustomDetailsView2 : GridViewRes {
public CustomDetailsView2() {
InitializeComponent();
} // it is interesting that if i set a breakpoint here i see my resourses - 2 items
}
public class GridViewRes : GridView {
public static DependencyProperty ResourcesProperty = DependencyProperty.Register(
"Resources",
typeof(ResourceDictionary),
typeof(CustomDetailsView2),
new FrameworkPropertyMetadata() {
DefaultValue = new ResourceDictionary()
});
public ResourceDictionary Resources {
get { return (ResourceDictionary)GetValue(ResourcesProperty); }
set { SetValue(ResourcesProperty, value); …Run Code Online (Sandbox Code Playgroud)