Hello,
I have a grid bound to a collection of items.
An item has several properties and one property is a combination of 4 properties (omitted INotifyPropertyChanged etc):
There are of course more properties available but the focus is on these properties mentioned.
Now, I tried creating a custom column which will, in view mode, display the FullNumber property and in edit mode create 4 masked text boxes to edit those 4 properties seperatly (Number, NumberSeperator, SubNumber and SubSubNumber)
So I figured the cleanest & easiest way to do this was to define 5 dependency properties on the custom column, 1 for each property, so that I could bind to them in my xaml code:
So my column looked a bit like this:
So when overriding the CreateCellEditElement function, I implemented is as such:
However, when using this column it will complain that it can't find the Number, NumberSeperator, SubNumber and SubSubNumber properties on the viewmodel, which is the datacontext of the grid.
I thought it would work the same as the DataMemberBinding and automatically use as datacontext, the row item.
Any help would be appreciated :)
I have a grid bound to a collection of items.
An item has several properties and one property is a combination of 4 properties (omitted INotifyPropertyChanged etc):
public class MyItemViewModel{ public int Number { get; set; } public string NumberSeperator { get; set; } public int SubNumber { get; set; } public string SubSubNumber { get; set; } public string FullNumber { get { return string.Format("{0}{1}{2}{3}", Number, NumberSeperator, SubNumber, SubSubNumber); } }}There are of course more properties available but the focus is on these properties mentioned.
Now, I tried creating a custom column which will, in view mode, display the FullNumber property and in edit mode create 4 masked text boxes to edit those 4 properties seperatly (Number, NumberSeperator, SubNumber and SubSubNumber)
So I figured the cleanest & easiest way to do this was to define 5 dependency properties on the custom column, 1 for each property, so that I could bind to them in my xaml code:
<MyCustomColumn NumberBinding="{Binding Number}" NumberSeperatorBinding="{Binding NumberSeperator}" SubNumberBinding="{Binding SubNumber}" SubSubNumberBinding="{Binding SubSubNumber}" />So my column looked a bit like this:
public class MyCustomColumn : GridViewBoundColumnBase{ public Binding NumberBinding { get { return (Binding)GetValue(NumberBindingProperty); } set { SetValue(NumberBindingProperty, value); } } public static readonly DependencyProperty NumberBindingProperty = DependencyProperty.Register("NumberBinding", typeof(Binding), typeof(MyCustomColumn), new PropertyMetadata(null)); public Binding NumberSeperatorBinding { get { return (Binding)GetValue(NumberSeperatorBindingProperty); } set { SetValue(NumberSeperatorBindingProperty, value); } } public static readonly DependencyProperty NumberSeperatorBindingProperty = DependencyProperty.Register("NumberSeperatorBinding", typeof(Binding), typeof(MyCustomColumn), new PropertyMetadata(null)); public Binding SubNumberBinding { get { return (Binding)GetValue(SubNumberBindingProperty); } set { SetValue(SubNumberBindingProperty, value); } } public static readonly DependencyProperty SubNumberBindingProperty = DependencyProperty.Register("SubNumberBinding", typeof(Binding), typeof(MyCustomColumn), new PropertyMetadata(null)); public Binding SubSubNumberBinding { get { return (Binding)GetValue(SubSubNumberBindingProperty); } set { SetValue(SubSubNumberBindingProperty, value); } } public static readonly DependencyProperty SubSubNumberBindingProperty = DependencyProperty.Register("SubSubNumberBinding", typeof(Binding), typeof(MyCustomColumn), new PropertyMetadata(null));}So when overriding the CreateCellEditElement function, I implemented is as such:
public override FrameworkElement CreateCellEditElement(GridViewCell cell, object dataItem) { var e1 = new RadMaskedNumericInput(); e1.SetBinding(RadMaskedNumericInput.ValueProperty, NumberBinding); var e2 = new RadMaskedTextInput(); e2.SetBinding(RadMaskedTextInput.ValueProperty, NumberSeperatorBinding); var e3 = new RadMaskedNumericInput(); e3.SetBinding(RadMaskedNumericInput.ValueProperty, SubNumberBinding); var e4 = new RadMaskedTextInput(); e4.SetBinding(RadMaskedTextInput.ValueProperty, SubSubNumberBinding); var wp = new WrapPanel(); wp.Children.Add(e1); wp.Children.Add(e2); wp.Children.Add(e3); wp.Children.Add(e4); return wp; }However, when using this column it will complain that it can't find the Number, NumberSeperator, SubNumber and SubSubNumber properties on the viewmodel, which is the datacontext of the grid.
I thought it would work the same as the DataMemberBinding and automatically use as datacontext, the row item.
Any help would be appreciated :)