or
Hi,
I have a RadGridview that contains a number of data columns and a custom column , which is basically a GridViewDataColumn user control that consists of a textbox and a button. If the user is editing a cell in one of the data column and then immediately clicks on the textbox in the custom column, the pervious cell is still on edit mode and the binding is not committed ( as the way if the user tabs always from the cell). How can I have the other cell updating the target binding if the user click on the texts box within the custom control.
Cheers
<
Window
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
x:Class
=
"RadSliderTest.MainWindow"
Title
=
"RadSlider TEST"
Width
=
"640"
Height
=
"320"
Background
=
"#FF393838"
TextBlock.Foreground
=
"White"
>
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
MinHeight
=
"48"
/>
<
RowDefinition
Height
=
"Auto"
MinHeight
=
"32"
/>
<
RowDefinition
Height
=
"Auto"
MinHeight
=
"48"
/>
<
RowDefinition
Height
=
"Auto"
MinHeight
=
"32"
/>
<
RowDefinition
Height
=
"Auto"
MinHeight
=
"48"
/>
<
RowDefinition
Height
=
"Auto"
MinHeight
=
"32"
/>
</
Grid.RowDefinitions
>
<
TextBlock
Margin
=
"8,8,8,2"
Text
=
"RadSlider(SelectionRangeEnable, Minimun:0.0, Maximum1.0) "
VerticalAlignment
=
"Bottom"
FontSize
=
"16"
FontWeight
=
"Bold"
/>
<
telerik:RadSlider
x:Name
=
"radSlider"
Margin
=
"8"
VerticalAlignment
=
"Center"
SelectionStart="{Binding RangeBegin,
Mode
=
TwoWay
,
UpdateSourceTrigger
=
PropertyChanged
,
RelativeSource={RelativeSource AncestorType={x:Type Window}} }"
SelectionEnd="{Binding RangeEnd,
Mode
=
TwoWay
,
UpdateSourceTrigger
=
PropertyChanged
,
RelativeSource={RelativeSource AncestorType={x:Type Window}} }"
IsSelectionRangeEnabled
=
"True"
Grid.Row
=
"1"
/>
<
TextBlock
Margin
=
"8,8,8,2"
Grid.Row
=
"2"
Text
=
"MainWindow DependencyProperty Binding"
VerticalAlignment
=
"Bottom"
FontSize
=
"16"
FontWeight
=
"Bold"
/>
<
Grid
Margin
=
"8"
Grid.Row
=
"3"
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"120"
/>
<
ColumnDefinition
Width
=
"*"
/>
<
ColumnDefinition
Width
=
"120"
/>
<
ColumnDefinition
Width
=
"*"
/>
</
Grid.ColumnDefinitions
>
<
TextBlock
Margin
=
"8"
Text
=
"RangeBegin"
VerticalAlignment
=
"Center"
HorizontalAlignment
=
"Right"
/>
<
TextBlock
Margin
=
"8"
Grid.Row
=
"1"
TextWrapping
=
"Wrap"
Text="{Binding RangeBegin,
Mode
=
TwoWay
,
UpdateSourceTrigger
=
PropertyChanged
,
RelativeSource={RelativeSource AncestorType={x:Type Window}} }"
VerticalAlignment
=
"Center"
Grid.Column
=
"1"
Foreground
=
"Black"
Background
=
"White"
/>
<
TextBlock
Margin
=
"8"
Text
=
"RangeEnd"
VerticalAlignment
=
"Center"
Grid.Column
=
"2"
HorizontalAlignment
=
"Right"
/>
<
TextBlock
Margin
=
"8"
Grid.Row
=
"1"
TextWrapping
=
"Wrap"
Text="{Binding RangeEnd,
Mode
=
TwoWay
,
UpdateSourceTrigger
=
PropertyChanged
,
RelativeSource={RelativeSource AncestorType={x:Type Window}} }"
VerticalAlignment
=
"Center"
Grid.Column
=
"3"
Foreground
=
"Black"
Background
=
"White"
/>
</
Grid
>
<
TextBlock
Margin
=
"8,8,8,2"
Grid.Row
=
"4"
Text
=
"ControlBinding"
VerticalAlignment
=
"Bottom"
FontSize
=
"16"
FontWeight
=
"Bold"
/>
<
Grid
Margin
=
"8"
Grid.Row
=
"5"
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"120"
/>
<
ColumnDefinition
Width
=
"*"
/>
<
ColumnDefinition
Width
=
"120"
/>
<
ColumnDefinition
Width
=
"*"
/>
</
Grid.ColumnDefinitions
>
<
TextBlock
Margin
=
"8"
Text
=
"SelectionStart"
VerticalAlignment
=
"Center"
HorizontalAlignment
=
"Right"
/>
<
TextBlock
Margin
=
"8"
Text
=
"{Binding SelectionStart, ElementName=radSlider}"
VerticalAlignment
=
"Center"
Grid.Column
=
"1"
Background
=
"White"
Foreground
=
"Black"
/>
<
TextBlock
Margin
=
"8"
Text
=
"SelectionEnd"
VerticalAlignment
=
"Center"
Grid.Column
=
"2"
HorizontalAlignment
=
"Right"
/>
<
TextBlock
Margin
=
"8"
Text
=
"{Binding SelectionEnd, ElementName=radSlider}"
VerticalAlignment
=
"Center"
Grid.Column
=
"3"
Background
=
"White"
Foreground
=
"Black"
/>
</
Grid
>
</
Grid
>
</
Window
>
using
System.Windows;
namespace
RadSliderTest
{
public
partial
class
MainWindow : Window
{
#region [RangeBegin] DependencyProperty
public
double
RangeBegin
{
get
{
return
(
double
)GetValue(RangeBeginProperty); }
set
{ SetValue(RangeBeginProperty, value); }
}
public
static
readonly
DependencyProperty RangeBeginProperty =
DependencyProperty.Register(
"RangeBegin"
,
typeof
(
double
),
typeof
(MainWindow),
new
PropertyMetadata(0.0));
#endregion
#region [RangeEnd] DependencyProperty
public
double
RangeEnd
{
get
{
return
(
double
)GetValue(RangeEndProperty); }
set
{ SetValue(RangeEndProperty, value); }
}
public
static
readonly
DependencyProperty RangeEndProperty =
DependencyProperty.Register(
"RangeEnd"
,
typeof
(
double
),
typeof
(MainWindow),
new
PropertyMetadata(1.0));
#endregion
public
MainWindow()
{
InitializeComponent();
}
}
}
I am trying to bind the background of the row to a variable in the datasource. I cannot seem to get it to work.
I am including the Xaml and Xaml.cs code to see if you can see what I am missing.
Reason for trying to bind to a variable is because I have a validate button in my program. It will return the ID of the invalid row
that will be highlighted in the treelistview... (the RowBGColor would be set to yellow ).
using
System.Collections.ObjectModel;
using
System.Windows;
using
System.Drawing;
namespace
TelerikRowBackground
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public
partial
class
MainWindow : Window
{
private
int
rowIndex = 1;
public
MainWindow()
{
InitializeComponent();
}
private
void
Button_Click(
object
sender, RoutedEventArgs e)
{
MessageBox.Show(
"Highlight Row: "
+ rowIndex);
//TODO: Change row background for rowIndex to Yellow.
// And reset previous hightlighted row.
if
(rowIndex == 3)
{
rowIndex = 1;
}
else
{
rowIndex++;
}
}
}
public
class
ViewModel
{
public
ObservableCollection<Model> AllData
{
get
{
return
new
ObservableCollection<Model>()
{
new
Model()
{
ID = 1,
RowBGColor = Color.Red,
Property1 =
"Test1.1"
,
Property2 =
"Test2.1"
,
Property3 =
"Test3.1"
,
Children =
new
ObservableCollection<Model>()
{
new
Model()
{
ID = 2,
RowBGColor = Color.Yellow,
Property1 =
"Test1.2"
,
Property2 =
"Test2.2"
,
Property3 =
"Test3.2"
,
Children =
new
ObservableCollection<Model>()
{
new
Model()
{
ID = 3,
RowBGColor = Color.Green,
Property1 =
"Test1.3"
,
Property2 =
"Test2.3"
,
Property3 =
"Test3.3"
}
}
}
}
}
};
}
}
}
public
class
Model
{
public
int
ID {
get
;
set
; }
public
string
Property1 {
get
;
set
; }
public
string
Property2 {
get
;
set
; }
public
string
Property3 {
get
;
set
; }
public
Color RowBGColor {
get
;
set
; }
private
ObservableCollection<Model> _children;
public
ObservableCollection<Model> Children
{
get
{
return
_children ?? (_children =
new
ObservableCollection<Model>()); }
set
{ _children = value; }
}
}
}
<Window x:Class=
"TelerikRowBackground.MainWindow"
xmlns:telerik=
"http://schemas.telerik.com/2008/xaml/presentation"
xmlns:local=
"clr-namespace:TelerikRowBackground"
Title=
"MainWindow"
Height=
"350"
Width=
"525"
>
<Window.Resources>
<local:ViewModel x:Key=
"MyViewModel"
/>
</Window.Resources>
<DockPanel DataContext=
"{StaticResource MyViewModel}"
>
<telerik:RadTreeListView Name=
"radTreeListView1"
DockPanel.Dock=
"Top"
Margin=
"5,5,0,0"
AutoGenerateColumns=
"False"
ItemsSource=
"{Binding AllData}"
VerticalAlignment=
"Top"
HorizontalAlignment=
"Left"
IsFilteringAllowed=
"False"
telerik:StyleManager.Theme=
"Windows7"
EnableColumnVirtualization=
"True"
EnableRowVirtualization=
"True"
AutoExpandGroups=
"True"
>
<telerik:RadTreeListView.ItemContainerStyle>
<Style TargetType=
"telerik:GridViewRowItem"
>
<Setter Property=
"Foreground"
Value=
"{Binding RowBGColor}"
/>
</Style>
</telerik:RadTreeListView.ItemContainerStyle>
<telerik:RadTreeListView.ChildTableDefinitions>
<telerik:TreeListViewTableDefinition ItemsSource=
"{Binding Children}"
/>
</telerik:RadTreeListView.ChildTableDefinitions>
<telerik:RadTreeListView.Columns>
<telerik:GridViewDataColumn x:Name=
"idColumn"
DataMemberBinding=
"{Binding ID, Mode=TwoWay }"
Header=
"ID"
/>
<telerik:GridViewDataColumn x:Name=
"prop1Column"
DataMemberBinding=
"{Binding Property1, Mode=TwoWay }"
Header=
"Property 1"
/>
<telerik:GridViewDataColumn x:Name=
"prop2Column"
DataMemberBinding=
"{Binding Property2, Mode=TwoWay }"
Header=
"Property 2"
/>
<telerik:GridViewDataColumn x:Name=
"prop3Column"
DataMemberBinding=
"{Binding Property3, Mode=TwoWay }"
Header=
"Property 3"
/>
</telerik:RadTreeListView.Columns>
</telerik:RadTreeListView>
<Button DockPanel.Dock=
"Bottom"
Height=
"50"
Click=
"Button_Click"
>Click to Highlight Row</Button>
</DockPanel>
</Window>
//Drag and Drop handlers to the result listview and ScheduleView
RadDragAndDropManager.AddDragQueryHandler(resultListView, OnDragQuery);
RadDragAndDropManager.SetAllowDrop(taskBoardScheduleView,
true
);
RadDragAndDropManager.AddDropInfoHandler(taskBoardScheduleView, OnDropInfo);
taskBoardScheduleView.DragDropBehavior =
new
TaskBoardDragDropBehavior();
protected
virtual
void
OnDropInfo(
object
sender, DragDropEventArgs e)
{
if
(e.Options.Status == DragStatus.DropComplete)
{
RefreshScheduleView();
//DateSpan dateSpan = new DateSpan(taskBoardScheduleView.VisibleRange.Start, taskBoardScheduleView.VisibleRange.End);
//viewModel.GetTaskAppointments(dateSpan);
}
}