Hi,
Can't seem to find the way to set CommandButtonsVisibility from code behind. I'm building a user control with dynamic behavior the DataForm.
In XAML it's easy and working.
Anybody that has an idea?
Thanks in advance!
Kurt
I have a RadDataForm with several DataFormDataFields and also some combo boxes.
I need to attach some event handlers to the fields that are triggered whenever the user starts to edit the text contents in a field. I am using a data template to define the fields included in the form. I would like to have, in my data template, something like this, for example:
<telerik:DataFormDataField Label="Client's Name"
Grid.Row="16"
Width="500" HorizontalAlignment="Left" TextChanged="DataFormDataField_TextChanged"
DataMemberBinding="{Binding PaymentRequest.ClientName, Mode=TwoWay}" />
and then in the code behind:
private void DataFormDataField_TextChanged(object sender, System.Windows.Input.TextCompositionEventArgs e)
{
etc....
}
Unfortunately, the DataFormDataField does not provide a TextChanged event. I have tried instead using the TextInput (or TextInputStart event). This fires fine when the user types additional text into the field, but the event does not get fired when, for example, the user presses the backspace delete key. I need an event that will fire whenever the pre-filled text starts to get changed. Any ideas?
Hi,
It would be extremely useful to have an virtual method that is called during the form's Validation process, that could be overridden to provide custom validation results to be injected into the ValidationSummary in place of the form's own validation. I've taken a look at some of the code and something like the following would be great. This is a small change to the existing code which I don't think would have any impact on other existing functionality:
/// <summary>
/// Checks if data current item is valid .
///
/// </summary>
///
/// <returns/>
public bool ValidateItem()
{
CollectionExtensions.RemoveItems<ErrorInfo>((ICollection<ErrorInfo>) this.validationErrors, (IEnumerable<ErrorInfo>) new List<ErrorInfo>(Enumerable.Where<ErrorInfo>((IEnumerable<ErrorInfo>) this.validationErrors, (Func<ErrorInfo, bool>) (ve => ve.IsItemLevelValidationError))));
List<ValidationResult> validationResults = new List<ValidationResult>();
if (this.CurrentItem != null)
{
try
{
validationResults.AddRange(GetValidationResults())
}
catch
{
return true;
}
}
CancelEventArgs e = new CancelEventArgs();
this.OnValidatingItem(e);
if (e.Cancel)
return false;
this.PopulateValidationErrors(validationResults);
return !EnumerableExtensions.IsNotEmpty((IEnumerable) this.validationErrors);
}
protected virtual IEnumerable<ValidationResult> GetValidationResults()
{
Validator.TryValidateObject(this.CurrentItem, new ValidationContext(this.CurrentItem, (IServiceProvider) null, (IDictionary<object, object>) null), (ICollection<ValidationResult>) validationResults, true);
}
<
telerik:DataFormComboBoxField
Grid.Row
=
"2"
MinHeight
=
"28"
ItemsSource
=
"{Binding VehicleCategories, Source={StaticResource locationVM}}"
DataMemberBinding
=
"{Binding VehicleCategory}"
DisplayMemberPath
=
"Label"
SelectedValuePath
=
"Code"
>
</
telerik:DataFormComboBoxField
>
<
telerik:DataFormComboBoxField
Grid.Row
=
"2"
MinHeight
=
"28"
>
<
telerik:DataFormComboBoxField.ContentTemplate
>
<
DataTemplate
>
<
telerik:RadComboBox
ItemsSource
=
"{Binding VehicleCategories, Source={StaticResource locationVM}}"
SelectedItem
=
"{Binding VehicleCategory}"
DisplayMemberPath
=
"Label"
SelectedValuePath
=
"Code"
/>
</
DataTemplate
>
</
telerik:DataFormComboBoxField.ContentTemplate
>
</
telerik:DataFormComboBoxField
>
<DataTemplate x:Key="Note_EditTemplate">
<StackPanel>
<telerik:DataFormDataField DataMemberBinding="{Binding Note, Mode=TwoWay}" Label="Note :" >
<TextBox Text="{Binding Note, Mode=TwoWay}" TextWrapping="Wrap" Height="100" Width="300" AcceptsReturn="True" MaxLength="1024"/>
</telerik:DataFormDataField>
<telerik:DataFormDataField DataMemberBinding="{Binding Created, StringFormat=d}" Label="Created :" IsReadOnly="True" />
<telerik:DataFormDataField DataMemberBinding="{Binding Modified, StringFormat=d}" Label="Modified :" IsReadOnly="True" />
</StackPanel>
</DataTemplate>
<telerik:RadDataForm Grid.Column="1" x:Name="data_UnitNotes" ItemsSource="{Binding UnitNotes.View}" VerticalAlignment="Top"
CommandButtonsVisibility="Add,Edit,Delete,Cancel,Commit" AutoGenerateFields="False" Margin="5,0,0,0"
AddedNewItem="data_UnitNotes_AddedNewItem_1" DeletedItem="data_UnitNotes_DeletedItem_1"
BeginningEdit="data_UnitNotes_BeginningEdit_1" EditEnded="data_UnitNotes_EditEnded_1"
EditTemplate="{StaticResource Note_EditTemplate}"
ReadOnlyTemplate="{StaticResource Note_ReadTemplate}"
NewItemTemplate="{StaticResource Note_EditTemplate}"/>
e.DataField = GetComboField(columnFieldProp, e.DataField.DataMemberBinding);
e.DataField.Loaded +=
delegate
(
object
o, RoutedEventArgs eventArgs)
{
var field = o
as
DataFormComboBoxField;
foreach
(RadComboBox child
in
field.ChildrenOfType<RadComboBox>())
{
var comboBox = child;
if
(comboBox !=
null
)
comboBox.SetBinding(RadComboBox.SelectedValueProperty, e.DataField.DataMemberBinding);
}
};
private DataFormComboBoxField GetComboField(ToolColumnFieldProp columnFieldProp, Binding dataBinding)
{
DataFormComboBoxField combo = new DataFormComboBoxField();
combo.SelectedValuePath = columnFieldProp.ComboBoxSelectedPath;
combo.DisplayMemberPath = columnFieldProp.ComboBoxDisplayPath;
object context = Code.Utility.CreateInstance(columnFieldProp.ComboBoxAssemblyName, columnFieldProp.ComboBoxContextNameSpace);
combo.ItemsSource = Code.Utility.GetComboBoxItemSource(context);
combo.DataMemberBinding = dataBinding;
return combo;
}
<
telerik:RadDataForm
x:Name
=
"rdDataForm"
Header
=
"{Binding Title}"
CurrentItem
=
"{Binding Current, Mode=TwoWay}"
telerik:StyleManager.Theme
=
"Office_Blue"
ItemsSource
=
"{Binding List, Mode=TwoWay}"
AutoGeneratingField
=
"rdDataForm_AutoGeneratingField"
Grid.Row
=
"0"
AutoCommit
=
"False"
EditEnded
=
"rdDataForm_EditEnded"
DeletedItem
=
"rdDataForm_DeletedItem"
CommandButtonsVisibility
=
"Cancel,Commit"
LabelPosition
=
"Beside"
>
</
telerik:RadDataForm
>