我怎样才能绑定进行依赖从Generic.xaml定义的资源字典定制控件的属性? [英] How can I bind to dependency properties of a custom control from a resource dictionary defined in Generic.xaml?

查看:183
本文介绍了我怎样才能绑定进行依赖从Generic.xaml定义的资源字典定制控件的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:我改写了整个问题

I rephrased the entire question.

大家好,

我有依赖属性的自定义控制。在Generic.xaml文件我有资源字典。这是外字典中的资源字典,像这样定义的:

I have a custom control with dependency properties. In the Generic.xaml file I have a resource dictionary. It's a resource dictionary within the outer dictionary, defined like so:

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyNamespace">

   <!-- This is the dictionary-->
   <ResourceDictionary x:Name="TheDictionaryImTalkingAbout" . . . >
   .
   .
   .
   </ResourceDictionary>
   .
   .
   .

</ResourceDictionary>

在此资源字典,TheDictionaryImTalkingAbout,我要绑定到我的控制依赖属性。我尝试了以下XAML:

In this resource dictionary, TheDictionaryImTalkingAbout, I want to bind to a dependency property of my control. I tried the following XAML :

<Object x:Key="MyObject" SomeProperty="{Binding MyDependencyProperty, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MyNamespace:MyControl}}}"/>

的结合没有返回的错误,但是,这是行不通的。谁能告诉我,我应该如何绑定到我父控件从资源字典内Generic.xaml这是内?

The binding returns no errors, however, it doesn't work. Can anyone tell me how I'm supposed to bind to my parent control from within a resource dictionary that's within Generic.xaml?

编辑:此结合的工作,但仅适用于某些属性。我无法渐变停止颜色结合型彩色的依赖项属性。它曾经工作的时候,这是一个用户控件,但现在不,现在我创建了一个自定义的控制工作。我不知道为什么,但如果你有兴趣,我问这个问题在这里:

This binding DOES work, but only for certain properties. I am unable to bind GradientStop Color to a dependency property of type color. It USED to work when this was a UserControl, but it doesn't work anymore now that I created a custom control. I don't know why, but if you're interested, I asked this question here:

<一个href=\"http://stackoverflow.com/questions/3472932/why-can-i-no-longer-bind-gradientstop-color-to-a-dependency-property-of-my-contro\">http://stackoverflow.com/questions/3472932/why-can-i-no-longer-bind-gradientstop-color-to-a-dependency-property-of-my-contro

谢谢大家谁帮助,

达拉尔

推荐答案

我已经看到了华尔街程序员答案。因此,我不知道到底,绑定将工作。但是,你与你绑定看到的问题是,你必须声明命名空间在您的用户控件,然后在绑定使用。

I have seen the answer from Wallstreet Programmer. Therefore, I don't know if in the end, the binding will work. But the problem that you see with your binding is, that you must declare the namespace where your UserControl is and then use this in the binding.

在你的XAML之上添加一个命名空间声明。如果命名空间是WindowsApplication,那么这将类似于如下:

Add a namespace-declaration on top of your xaml. If the namespace is "WindowsApplication" then this will look like follows:

xmlns:local="clr-namespace:WindowsApplication"

然后在绑定,写

<GradientStop Color="{Binding Scheme, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MyControl}}}" Offset="0"/>  

这篇关于我怎样才能绑定进行依赖从Generic.xaml定义的资源字典定制控件的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆