0

我可以将绑定与 SL5 RC 标记扩展一起使用吗?

这是我的 XAML:

...
    <TextBlock>
                <TextBlock.Text>
                   <local:LengtherMarkupExtension Test="{Binding ElementName='MyTextBox', Path='Text'}" />
                </TextBlock.Text>
            </TextBlock>
...

我:

public class LengtherMarkupExtension: FrameworkElement,
        IMarkupExtension<string>
    {
        public LengtherMarkupExtension()
        {
            //this.DataContext = this;
        }


        public static readonly DependencyProperty TestProperty =
            DependencyProperty.Register("Test",
                typeof(string),
                typeof(LengtherMarkupExtension),
                new PropertyMetadata("DefaultValue",
                    (o, e) => 
                    {
                        System.Diagnostics.Debugger.Break();
                    }));


        public string Test
        {
            get { return (string)this.GetValue(LengtherMarkupExtension.TestProperty); }
            set { this.SetValue(LengtherMarkupExtension.TestProperty, value); }
        }


        public string ProvideValue(IServiceProvider serviceProvider)
        {
            return this.Test.Length.ToString();
        }
    }

无论如何,我的 ME 的测试属性都不会通过绑定设置,我做错了吗?

4

1 回答 1

0

XAML 解析器在解析过程中调用标记扩展,此时无法解析绑定。根据您的示例,您可能想要返回绑定。

于 2011-09-14T17:57:14.220 回答