Hi,
I seem to be unable to get the databinding to work so that, for example, the background colour of a grid cell is set to the colour property of a business object. Please can someone take a look and show me the error of my ways?
ORM version 2013.2.702.1
RadControls for WPF version 2013.2.724.40
In summary, I am getting a list back from the database using a stored procedure mapped to a domain method. I have also added a partial class and a transient property to the result item in my ORM library. This transient property is a System.Windows.Media.Color and the values are stored in an XML file that are merged with the database result by my view model prior to the view being presented.
In my attempt to understand why the colour is not set, I am showing the ToString result in the cell so I know the colour value is present, however, the colour of the cell remains white.
Here's my ORM partial class:
Here's the XAML cut down for brevity:
I've attached a sample of the output view.
I've since worked on a very simple test project to try to reproduce the problem but I cannot. The test app works. I changed the cell template in the problem app to match the working test app as follows:
This made no difference. The backgound color remains white.
Further to this, I've increased the trace level to high and get this output for the SolidColorBrush binding:
Doesn't this show that it has found the Color property?
Any suggestions please?
Thanks
Craig
I seem to be unable to get the databinding to work so that, for example, the background colour of a grid cell is set to the colour property of a business object. Please can someone take a look and show me the error of my ways?
ORM version 2013.2.702.1
RadControls for WPF version 2013.2.724.40
In summary, I am getting a list back from the database using a stored procedure mapped to a domain method. I have also added a partial class and a transient property to the result item in my ORM library. This transient property is a System.Windows.Media.Color and the values are stored in an XML file that are merged with the database result by my view model prior to the view being presented.
In my attempt to understand why the colour is not set, I am showing the ToString result in the cell so I know the colour value is present, however, the colour of the cell remains white.
Here's my ORM partial class:
using System;
using System.Linq;
using System.Windows.Media;
namespace xyz
{
public partial class DBLISTitem
{
[Telerik.OpenAccess.Transient]
private Color _patternColour;
public Color PatternColour
{
get
{
return _patternColour;
}
set
{
_patternColour = value;
}
}
}
}
Here's the XAML cut down for brevity:
<
UserControl
x:Class
=
"..."
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable
=
"d"
d:DesignHeight
=
"300"
d:DesignWidth
=
"300"
>
<
Grid
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
/>
<
ColumnDefinition
Width
=
"5"
/>
<
ColumnDefinition
Width
=
"*"
/>
</
Grid.ColumnDefinitions
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"*"
/>
<
RowDefinition
Height
=
"30"
/>
<
RowDefinition
Height
=
"30"
/>
</
Grid.RowDefinitions
>
<
Grid.Resources
>
<
telerik:ColorToBrushConverter
x:Key
=
"ColorToBrushConverter"
/>
</
Grid.Resources
>
<
telerik:RadGridView
Name
=
"ocyMapyGrid"
Grid.Column
=
"0"
Grid.Row
=
"0"
Grid.ColumnSpan
=
"3"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Stretch"
Width
=
"Auto"
IsFilteringAllowed
=
"False"
CanUserSortColumns
=
"True"
CanUserSortGroups
=
"True"
ItemsSource
=
"{Binding DBLIST, Mode=TwoWay}"
AutoGenerateColumns
=
"False"
ShowGroupPanel
=
"False"
ShowInsertRow
=
"False"
RowHeight
=
"23"
RowIndicatorVisibility
=
"Collapsed"
ScrollViewer.HorizontalScrollBarVisibility
=
"Disabled"
CanUserFreezeColumns
=
"False"
CanUserReorderColumns
=
"False"
CanUserResizeColumns
=
"True"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding ColName}"
Header
=
"Col1"
Width
=
"*"
/>
<
telerik:GridViewDataColumn
Header
=
"Colour"
Width
=
"150"
>
<
telerik:GridViewDataColumn.CellTemplate
>
<
DataTemplate
>
<
TextBlock
Text
=
"{Binding Path=PatternColour}"
Background
=
"{Binding Path=PatternColour, Converter={StaticResource ColorToBrushConverter}}"
Margin
=
"0"
/>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellTemplate
>
</
telerik:GridViewDataColumn
>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
</
Grid
>
</
UserControl
>
I've attached a sample of the output view.
I've since worked on a very simple test project to try to reproduce the problem but I cannot. The test app works. I changed the cell template in the problem app to match the working test app as follows:
<
telerik:GridViewDataColumn.CellTemplate
>
<
DataTemplate
>
<
TextBlock
Text
=
"{Binding Path=HatchPatternColour}"
Margin
=
"0"
>
<
TextBlock.Background
>
<
SolidColorBrush
Color
=
"{Binding Path=HatchPatternColour}"
/>
</
TextBlock.Background
>
</
TextBlock
>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellTemplate
>
Further to this, I've increased the trace level to high and get this output for the SolidColorBrush binding:
System.Windows.Data Warning: 54 : Created BindingExpression (hash=20902088)
for
Binding (hash=2322454)
System.Windows.Data Warning: 56 : Path:
'HatchPatternColour'
System.Windows.Data Warning: 58 : BindingExpression (hash=20902088): Default mode resolved to OneWay
System.Windows.Data Warning: 59 : BindingExpression (hash=20902088): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 60 : BindingExpression (hash=20902088): Attach to System.Windows.Media.SolidColorBrush.Color (hash=53901065)
System.Windows.Data Warning: 62 : BindingExpression (hash=20902088): Use Framework mentor <
null
>
System.Windows.Data Warning: 65 : BindingExpression (hash=20902088): Resolving source
System.Windows.Data Warning: 67 : BindingExpression (hash=20902088): Framework mentor not found
System.Windows.Data Warning: 63 : BindingExpression (hash=20902088): Resolve source deferred
System.Windows.Data Warning: 93 : BindingExpression (hash=20902088): Got InheritanceContextChanged
event
from SolidColorBrush (hash=53901065)
System.Windows.Data Warning: 65 : BindingExpression (hash=20902088): Resolving source
System.Windows.Data Warning: 68 : BindingExpression (hash=20902088): Found data context element: TextBlock (hash=15347538) (OK)
System.Windows.Data Warning: 69 : BindingExpression (hash=20902088): DataContext
is
null
System.Windows.Data Warning: 65 : BindingExpression (hash=20902088): Resolving source
System.Windows.Data Warning: 68 : BindingExpression (hash=20902088): Found data context element: TextBlock (hash=15347538) (OK)
System.Windows.Data Warning: 76 : BindingExpression (hash=20902088): Activate with root item TopLevelAccountCode (hash=28952916)
System.Windows.Data Warning: 106 : BindingExpression (hash=20902088): At level 0 -
for
TopLevelAccountCode.HatchPatternColour found accessor ReflectPropertyDescriptor(HatchPatternColour)
System.Windows.Data Warning: 102 : BindingExpression (hash=20902088): Replace item at level 0 with TopLevelAccountCode (hash=28952916),
using
accessor ReflectPropertyDescriptor(HatchPatternColour)
System.Windows.Data Warning: 99 : BindingExpression (hash=20902088): GetValue at level 0 from TopLevelAccountCode (hash=28952916)
using
ReflectPropertyDescriptor(HatchPatternColour): Color (hash=1871599772)
System.Windows.Data Warning: 78 : BindingExpression (hash=20902088): TransferValue - got raw value Color (hash=1871599772)
System.Windows.Data Warning: 87 : BindingExpression (hash=20902088): TransferValue -
using
final value Color (hash=1871599772)
Any suggestions please?
Thanks
Craig