, . WPF, , xaml.
TemplateBinding instad of Normal Binding? , , DataTemplates.
ContentPresenter, , , Text string...
Edit:
, , ...
:
<Application.Resources>
<LabelTest:ContentToTextConverter x:Key="contentConverter" />
<Style TargetType="Label">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Label">
<TextBox DataContext="{Binding Mode=OneWay, RelativeSource={RelativeSource FindAncestor,AncestorType=Label}}">
<TextBox.Text>
<MultiBinding Converter="{StaticResource contentConverter}" >
<Binding Mode="OneWay" Path="ContentStringFormat" />
<Binding Mode="OneWay" Path="Content" />
</MultiBinding>
</TextBox.Text>
</TextBox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
ContentToTextConverter :
public class ContentToTextConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var format = values[0] as string;
if (string.IsNullOrEmpty(format)) format = "{0}";
else if(format.IndexOf('{') < 0) format = "{0:" + format + "}";
return string.Format(culture, format, values[1]);
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
:
<Label ContentStringFormat="{}{0}$">
<System:Int64>15</System:Int64>
</Label>
, , .