I have a custom UserControl with a DataGrid and a TextBox, I am trying to databind things to these elements using DependencyProperties. The binding works fine for the DataGrid but not for the TextBox.
Code:
public static readonly DependencyProperty BuiDataProperty = DependencyProperty.Register("BuiData", typeof(IEnumerable), typeof(BelastingTab), new PropertyMetadata(default(IEnumerable), BuiDataChanged));
private static void BuiDataChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var Object = d as BelastingTab;
if (Object == null) return;
Object.BuiDataDataSourceChanged(d, e);
}
private void BuiDataDataSourceChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
BuiDataTabel.ItemsSource = dependencyPropertyChangedEventArgs.NewValue as IEnumerable;
}
public IEnumerable BuiData
{
get { return (IEnumerable)GetValue(BuiDataProperty); }
set { SetValue(BuiDataProperty, value); }
}
And in the main XAML:
<src:BelastingTab BuiData="{Binding Path=Static.BuienRegulier[0].BuiTabel}"/>
This is the code for setting the binding of the DataGrid, how would I go about doing the same for the TextBox?
EDIT: This is what I have currently,
Main XAML:
<src:BelastingTab BuiData="{Binding Path=Static.BuienRegulier[0].BuiTabel}" HerhalingsTijd="{Binding Path=Static.BuienRegulier[0].HerhalingsTijd}"/>
This refers to a string. In the UserControl XAML:
<TextBox Text="{Binding HerhalingsTijd, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
In the UserControl XAML CS:
public static readonly DependencyProperty HerhalingsTijdProperty = DependencyProperty.Register("HerhalingsTijd", typeof(string), typeof(BelastingTab), new PropertyMetadata(string.Empty));
public string HerhalingsTijd
{
get { return (string)GetValue(HerhalingsTijdProperty); }
set { SetValue(HerhalingsTijdProperty, value); }
}