开发者

MultiBinding to the Title Property of a wpf user control?

I need to format the Title property of my user control. For this I am trying to make use of MultiBinding with StringFormat.

The Xaml I use is :

<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>

For some reason this does not seem to work. Am I missing something here? Thanks开发者_C百科!


I would recommend binding the Title property to a property on a ViewModel if using MVVM or just a property on the code behind if not.

<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); }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜