Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将静态方法分配给xaml中委托类型的DependencyProperty_C#_Wpf - Fatal编程技术网

C# 将静态方法分配给xaml中委托类型的DependencyProperty

C# 将静态方法分配给xaml中委托类型的DependencyProperty,c#,wpf,C#,Wpf,我的类中有委托类型的依赖属性MyEditBox: public delegate int LengthFilterDelegate(string text, int length); public static readonly DependencyProperty LengthFilterProperty = DependencyProperty.Register("LengthFilter", typeof(LengthFilterDelegate), typeof(MyEdit

我的类中有委托类型的依赖属性
MyEditBox

public delegate int LengthFilterDelegate(string text, int length);

public static readonly DependencyProperty LengthFilterProperty = 
    DependencyProperty.Register("LengthFilter", typeof(LengthFilterDelegate), typeof(MyEditBox), 
    new PropertyMetadata(new LengthFilterDelegate(lengthFilter)));

public LengthFilterDelegate LengthFilter
{
    get { return ((LengthFilterDelegate)(GetValue(LengthFilterProperty))); }
    set { SetValue(LengthFilterProperty, value); }
}

private static int lengthFilter(string text, int length)
{
    return 10;
}
我想使用样式设置器为另一个类的静态方法赋值:

<Style TargetType="myns:MyEditBox">
    <Setter Property="LengthFilter" Value="{x:Static myns:TextWidthAutocadResolver.Resolve}"/>
</Style>

但由于某些原因,编译器无法找到
Resolve
方法。我做错了什么?

x:Static标记扩展可以引用。是的,这是问题的根源,现在我添加了
public Static Common.LimitedTextBox.LengthFilterDelegate resolvedDelegate=new Common.LimitedTextBox.LengthFilterDelegate(Resolve)
并使用它代替xaml中的
Resolve
。你可以写你的评论作为回答。
public static class TextWidthAutocadResolver
{
    public static int Resolve(string text, int length)
    {
        return 5;
    }
}