I have a problem with binding a property of a custom control of me to a Value of my mainform. I already used the DependencyProperties and it works in an old control of mine, but in the current control it doesn't work and I have no idea why not. My current code for the property of my form with the value, that should be binded to the custom control:
private ObservableCollection<ConnectionItem> _ConList = new ObservableCollection<ConnectionItem>();
public ObservableCollection<ConnectionItem> ConList
{
get { return _ConList; }
set
{
_ConList = value;
triggerPropertyChanged("ConList");
}
}
the XAML-Code for this looks like this:
<Fluent:RibbonWindow
x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Fluent="clr-namespace:Fluent;assembly=Fluent"
Title="Test"
Height="600"
Width="800"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
>
<Grid>
<aTreeView Name="tvConList" Items="{Binding ConList}" />
</Grid>
</Fluent:RibbonWindow>
My Custom-Control has this code:
public partial class aTreeView : INotifyPropertyChanged
{
public aTreeView()
{
InitializeComponent();
}
public static readonly DependencyProperty ItemsProperty =
DependencyProperty.Register(
"Items",
typeof(ObservableCollection<ConnectionItem>),
typeof(aTreeView),
new PropertyMetadata(new ObservableCollection<ConnectionItem>())
);
private ObservableCollection<ConnectionItem> _Items;
/// <summary>
/// Gets the current Items
/// </summary>
public ObservableCollection<ConnectionItem> Items
{
get
{
return ((ObservableCollection<ConnectionItem>)GetValue(ItemsProperty));
//return _Items;
}
set
{
SetValue(ItemsProperty, value);
//_Items = value;
}
}
}
With this code, there are not compiling-Failures (except I did Copy-Paste-mistakes) but the get/set of the Items-Property of the Control will never executed, if I set some breakpoints to this.