为代码中的xaml元素设置多线程 [英] Set multibinding for a xaml element in code behind

查看:141
本文介绍了为代码中的xaml元素设置多线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下工作的XAML代码,基本上绑定了几个属性来计算用户控件的最终位置:

I have the following working XAML code that basically binds a couple of properties to calculate the final position of my user control:

<UserControl x:Class="CurvePointControl"
    ....
         >
<UserControl.Resources>
    <local:VToYConverter x:Key="vToYConverter" />
</UserControl.Resources>
<UserControl.RenderTransform>
    <TranslateTransform x:Name="XTranslateTransform" >
        <TranslateTransform.Y>
            <MultiBinding Converter="{StaticResource vToYConverter}">
                <Binding ElementName="curveEditPoint" Path="V"/>
                <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type local:CurveEditor}}" Path="MinV"/>
                <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type local:CurveEditor}}" Path="MaxV"/>
                <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type local:CurveEditor}}" Path="ActualHeight"/>                    
            </MultiBinding>
        </TranslateTransform.Y>
    </TranslateTransform>
</UserControl.RenderTransform>

...

...

由于各种原因(但是为了避免相对来源,我现在正试图在代码中执行相同的操作,而无需成功。

For various reasons (but esp to avoid the relative source, I am now trying to do the same in code behind without success.

这是我当前的代码: p>

This is my current code:

    public CurvePointControl(CurveEditor CV)
    {
        InitializeComponent();

        MultiBinding multiBinding = new MultiBinding();
        multiBinding.Converter = m_VToYConverter;

        multiBinding.Bindings.Add(new Binding("V"));
        multiBinding.Bindings.Add(new Binding(CV.MinVProperty)); // doesn't work
        multiBinding.Bindings.Add(new Binding(CV.MaxVProperty)); // doesn't work
        multiBinding.Bindings.Add(new Binding(CV.ActualHeight)); // doesn't work       
        multiBinding.NotifyOnSourceUpdated= true;

        this.SetBinding(TranslateTransform.YProperty, multiBinding);
        //Doesn't work too:
        //BindingOperations.SetBinding(XTranslateTransform, TranslateTransform.YProperty, multiBinding);

    }

我仍然不能相信这是很难将XAML转换为c#代码。转换器被调用,但只有一次,没有有效的属性值。

I still can't believe that it is so hard to convert the XAML into c# code. The converter is called but only once and without valid property values.

任何想法是什么问题?
我如何调试这样的问题?

Any idea of what's wrong? How could I debug such a problem?

推荐答案

您需要来源:

multiBinding.Bindings.Add(new Binding("V") { Source = curveEditPoint }); //If that object is accessible in the current scope.
multiBinding.Bindings.Add(new Binding("MinV") { Source = CV });
multiBinding.Bindings.Add(new Binding("MaxV") { Source = CV });
multiBinding.Bindings.Add(new Binding("ActualHeight") { Source = CV });

这篇关于为代码中的xaml元素设置多线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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