I have this XAML:
<Label Text="{Binding val1, StringFormat={StaticResource CommaInteger}}"/>
<Label Text="{Binding val2, StringFormat={StaticResource CommaInteger}}"/>
I want to simplify it to:
<local:commaIntLbl Text="{Binding val1}"/>
<local:commaIntLbl Text="{Binding val2}"/>
How should I code my commaIntLbl class to achieve this?
public class commaIntLbl : Label
{
public commaIntLbl() : base()
{
SetDynamicResource(StyleProperty, "IntegerLabel");
// How to refer its Text's string-format to the StaticResource CommaInteger?
}
}
You could set the string format in val1 property like below and then do the binding.
Update:
Xaml:
Custom Control:
Code behind: