开发者

MultiBinding to the Title Property of a wpf user control?

开发者 https://www.devze.com 2023-01-30 08:32 出处:网络
I need to format the Title property of my user control. For this I am trying to make use of MultiBinding with StringFormat.

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

精彩评论

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