Hi,
I want to create custom control which is simply occurs a grid and contains rectangle elements. I want to make databinding for the rectangle elements. Therefore I create a custom class for my grid and has a dependency property for Rectangle objects.
public class MyGrid : Grid { public static readonly DependencyProperty TimeInformationContentProperty = DependencyProperty.Register("TimeInformationContent", typeof(ObservableCollection<Rectangle>), typeof(MyGrid), new PropertyMetadata(new ObservableCollection<Rectangle>() ) ); public ObservableCollection<Rectangle> TimeInformationContent { get { return (ObservableCollection<Rectangle>)GetValue(TimeInformationContentProperty); } set { SetValue(TimeInformationContentProperty, value); } } }
Now I create a new UserControl ie. TimeControl.cs, and this control has the same DependencyProperty above. In XAML part i write:
<main:MyGrid TimeInformationContent="{Binding Path=TimeInformationContent, ElementName= Root_Part}" />
for databinding.
Then I want to use this UserContol in the MainWindow and i write this:
<Window.DataContext><main:ViewModel /></Window.DataContext><Grid><Grid.RowDefinitions><RowDefinition Height="auto" /><RowDefinition Height="*" /></Grid.RowDefinitions><main:TimeControl TimeInformationContent="{Binding RectangleContent, Mode=TwoWay}" Height="50" /></Grid>
which in ViewModel part i have an ObservableCollection for the rectangles.
Here is the questin: this code does not work.
Is there a simple mistake? or the concept for this scenario is totaly wrong?
King Regards