【问题标题】:MultiBinding to the Title Property of a wpf user control?多绑定到 wpf 用户控件的标题属性?
【发布时间】:2010-12-10 00:18:55
【问题描述】:

我需要格式化我的用户控件的 Title 属性。为此,我尝试将 MultiBinding 与 StringFormat 结合使用。

我使用的 Xaml 是:

<Control x:Name="myControlName">
    <Control.Title>
        <MultiBinding StringFormat="You have {0} of {1} items. ">
            <Binding Path="MyNumber"></Binding>
            <Binding Path="TotalNumber"></Binding>
        </MultiBinding>
    </Control.Title>
</Control>

由于某种原因,这似乎不起作用。 我在这里错过了什么吗?谢谢!

【问题讨论】:

  • 嘿...谢谢乔伊...我无法正确获取代码标签... :)
  • 是的,这很明显;-)。编辑器上方的工具栏中还有一个不错的 »code« 按钮。它现在只是在 IE 9 beta 中被破坏。
  • 你能说得更具体些吗?我没明白你想要做什么

标签: wpf xaml binding


【解决方案1】:

如果使用 MVVM,我建议将 Title 属性绑定到 ViewModel 上的一个属性,或者如果不使用,则只将一个属性绑定到后面的代码上。

<Control x:Name="myControlName" Title={Binding Path=MyTitle}>

</Control>

public class MyView
{
    public int MyNumber { get; set; }
    public int TotalNumber { get; set; }
    public string MyTitle 
    {
        get { return string.Format("You have {0} of {1} items. ", MyNumber, TotalNumber); }
    }
}

【讨论】:

    猜你喜欢
    • 2011-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多