В динамически построенном UserControl
я установил format string
для TextBox
таким образом:
TextBox newTextBox = new TextBox();
TempViewModel viewModel = new TempViewModel();
var binding = new System.Windows.Data.Binding
{
Source = viewModel,
Path = new PropertyPath("DecimalValue"),
ConverterCulture = new System.Globalization.CultureInfo("de-DE"),
StringFormat = "{0:#,##0.00}"
};
newTextBox.SetBinding(TextBox.TextProperty, binding);
public class TempViewModel
{
public decimal DecimalValue { get; set; }
}
Пока все отлично работает.
Но после добавления свойства DependencyProperty формат игнорируется .Dependencyproperty
определяется следующим образом:
public class UserControl_CBOGridQuotePositions : UserControl
{
private static readonly DependencyProperty Amount_QuotePos_Base_DependencyProperty =
DependencyProperty.Register("Amount_QuotePos_Base", typeof(System.Decimal), typeof(UserControl_CBOGridQuotePositions), new PropertyMetadata(0m));
public System.Decimal Amount_QuotePos_Base
{
get { return (System.Decimal)GetValue(UserControl_CBOGridQuotePositions.Amount_QuotePos_Base_DependencyProperty); }
set { SetValue(UserControl_CBOGridQuotePositions.Amount_QuotePos_Base_DependencyProperty, value); }
}
private void MakeTheBindings(DependencyProperty dependencyProperty)
{
var binding = new Binding("Amount_QuotePos_Base");
binding.Source = this; // which is the UserControl_CBOGridQuotePositions
newTextBox.SetBinding(dependencyProperty, binding);
}
}
Есть ли способ заставить формат работать, пока TextBox привязан к свойству?