简体   繁体   English

WPF和C#-在后面的代码中创建x:static绑定

[英]WPF and C# - Create x:static binding in code behind

Even if similar questions are already posted, I still haven't found a solution. 即使已经发布了类似的问题,我仍然没有找到解决方案。 In XAML I have this kind of "binding" that works good: 在XAML中,我有这种很好的“绑定”功能:

<Controls:MyCustomControl MyCustomAction="{x:Static staticTest:TestDelegate.myConverterAction}" [...]>

Now, I need to set the MyCustomAction property (that is a delegate property) in this way but via code. 现在,我需要通过代码以这种方式设置MyCustomAction属性(这是一个委托属性)。 Is there a way to make a x:Static bind in XAML using C#? 有没有一种方法可以使用C#在XAML中进行x:Static绑定?

The equivalent of you XAML in C# code would simply be: 在C#代码中,等效于您的XAML就是:

MyCustomControl mcc = ...;

mcc.MyCustomAction = TestDelegate.myConverterAction;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM