Hello,
I'm trying to have a custom DataFormDataField. Therefore I followed the tutorial on
https://docs.telerik.com/devtools/wpf/controls/raddataform/getting-started/defining-custom-datafields
since my own approach didn't work, I just started over and tried exactly the code from the documentation. It is still not working.
I tried autogeneratedfields and with datatemplate. In Both cases the custom datafield didn't show. The Visiual Tree is showing the Object as a Child of the RadDataForm but not as a DataFormdataField.
After a while I realized that GetControl() is not called. Can you confirm the Problem for Assembly Telerik.Windows.Controls.Data, Version 2017.3.913.45?
Thanks in advance.
sincerely,
Michael
5 Answers, 1 is accepted
I got a workaround for now, but I would like to have a clean solution for this.
Right now it is running like that:
public class DataFormNumericUpDownField : DataFormDataField
{
protected override DependencyProperty GetControlBindingProperty()
{
return RadNumericUpDown.ValueProperty;
}
public new Control GetControl()
{
DependencyProperty dependencyProperty = this.GetControlBindingProperty();
RadNumericUpDown numericUpDown = new RadNumericUpDown();
if (this.DataMemberBinding != null)
{
var binding = this.DataMemberBinding;
numericUpDown.SetBinding(dependencyProperty, binding);
}
numericUpDown.SetBinding(RadNumericUpDown.IsEnabledProperty, new Binding("IsReadOnly") { Source = this, Converter = new InvertedBooleanConverter() });
return numericUpDown;
}
}
private
void
RadDataForm_AutoGeneratingField(
object
sender, Telerik.Windows.Controls.Data.DataForm.AutoGeneratingFieldEventArgs e)
{
if
(e.DataField.Label.Equals(
"Number"
))
{
e.DataField.Content =
(new
DataFormNumericUpDownField() { Label = e.DataField.Label, DataMemberBinding = e.DataField.DataMemberBinding }).GetControl();
}
}
I'm pretty sure this is not the way a custom DataField is supposed to be created. But it seems to be working.
sincerely,
Michael
I've attached a small sample project based on the article you provided where the GetControl override is called as expected and the custom control is generated.
Could you please have a look at it and let me know how it differs from the setup you have at your end? I look forward to your reply.
Regards,
Dilyan Traykov
Progress Telerik
@Dilyan How to make custom DataFormDataField work with Binaries.NoXaml assembly? I modified your projected to use Binaries.NoXaml assembly, and the custom DataFormDataField does not display.
App.xaml:
<
Application
x:Class
=
"CustomDataFormDataField.App"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
StartupUri
=
"MainWindow.xaml"
>
<
Application.Resources
>
<
ResourceDictionary
>
<
ResourceDictionary.MergedDictionaries
>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Office2013;component/Themes/System.Windows.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Office2013;component/Themes/Telerik.Windows.Controls.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Office2013;component/Themes/Telerik.Windows.Controls.Input.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Office2013;component/Themes/Telerik.Windows.Controls.GridView.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Office2013;component/Themes/Telerik.Windows.Controls.Navigation.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Office2013;component/Themes/Telerik.Windows.Controls.Data.xaml"
/>
</
ResourceDictionary.MergedDictionaries
>
</
ResourceDictionary
>
</
Application.Resources
>
</
Application
>
references in csproj file:
<
ItemGroup
>
<
Reference
Include
=
"System"
/>
<
Reference
Include
=
"System.Data"
/>
<
Reference
Include
=
"System.Xml"
/>
<
Reference
Include
=
"Microsoft.CSharp"
/>
<
Reference
Include
=
"System.Core"
/>
<
Reference
Include
=
"System.Xml.Linq"
/>
<
Reference
Include
=
"System.Data.DataSetExtensions"
/>
<
Reference
Include
=
"System.Xaml"
>
<
RequiredTargetFramework
>4.5</
RequiredTargetFramework
>
</
Reference
>
<
Reference
Include
=
"Telerik.Windows.Controls, Version=2018.1.220.45, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL"
>
<
SpecificVersion
>False</
SpecificVersion
>
<
HintPath
>C:\Program Files (x86)\Progress\Telerik UI for WPF R1 2018\Binaries.NoXaml\WPF40\Telerik.Windows.Controls.dll</
HintPath
>
</
Reference
>
<
Reference
Include
=
"Telerik.Windows.Controls.Chart, Version=2018.1.220.45, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL"
>
<
SpecificVersion
>False</
SpecificVersion
>
<
HintPath
>C:\Program Files (x86)\Progress\Telerik UI for WPF R1 2018\Binaries.NoXaml\WPF40\Telerik.Windows.Controls.Chart.dll</
HintPath
>
</
Reference
>
<
Reference
Include
=
"Telerik.Windows.Controls.Data, Version=2018.1.220.45, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL"
>
<
SpecificVersion
>False</
SpecificVersion
>
<
HintPath
>C:\Program Files (x86)\Progress\Telerik UI for WPF R1 2018\Binaries.NoXaml\WPF40\Telerik.Windows.Controls.Data.dll</
HintPath
>
</
Reference
>
<
Reference
Include
=
"Telerik.Windows.Controls.GridView, Version=2018.1.220.45, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL"
>
<
SpecificVersion
>False</
SpecificVersion
>
<
HintPath
>C:\Program Files (x86)\Progress\Telerik UI for WPF R1 2018\Binaries.NoXaml\WPF40\Telerik.Windows.Controls.GridView.dll</
HintPath
>
</
Reference
>
<
Reference
Include
=
"Telerik.Windows.Controls.Input, Version=2018.1.220.45, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL"
>
<
SpecificVersion
>False</
SpecificVersion
>
<
HintPath
>C:\Program Files (x86)\Progress\Telerik UI for WPF R1 2018\Binaries.NoXaml\WPF40\Telerik.Windows.Controls.Input.dll</
HintPath
>
</
Reference
>
<
Reference
Include
=
"Telerik.Windows.Controls.Navigation, Version=2018.1.220.45, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL"
>
<
SpecificVersion
>False</
SpecificVersion
>
<
HintPath
>C:\Program Files (x86)\Progress\Telerik UI for WPF R1 2018\Binaries.NoXaml\WPF40\Telerik.Windows.Controls.Navigation.dll</
HintPath
>
</
Reference
>
<
Reference
Include
=
"Telerik.Windows.Data, Version=2018.1.220.45, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL"
>
<
SpecificVersion
>False</
SpecificVersion
>
<
HintPath
>C:\Program Files (x86)\Progress\Telerik UI for WPF R1 2018\Binaries.NoXaml\WPF40\Telerik.Windows.Data.dll</
HintPath
>
</
Reference
>
<
Reference
Include
=
"Telerik.Windows.Themes.Office2013"
>
<
HintPath
>C:\Program Files (x86)\Progress\Telerik UI for WPF R1 2018\Binaries.NoXaml\WPF40\Telerik.Windows.Themes.Office2013.dll</
HintPath
>
</
Reference
>
<
Reference
Include
=
"WindowsBase"
/>
<
Reference
Include
=
"PresentationCore"
/>
<
Reference
Include
=
"PresentationFramework"
/>
</
ItemGroup
>
Please refer to the Styling Custom Controls section where this scenario has been explained. In this case, you need to add the following line after you merge the required resource dictionaries:
<
ResourceDictionary
>
<
ResourceDictionary.MergedDictionaries
>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Office_Black;component/Themes/System.Windows.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.Data.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.Input.xaml"
/>
</
ResourceDictionary.MergedDictionaries
>
<
Style
TargetType
=
"local:DataFormNumericUpDownField"
BasedOn
=
"{StaticResource DataFormDataFieldStyle}"
/>
</
ResourceDictionary
>
Please let me know if this displays the custom field as expected.
Regards,
Dilyan Traykov
Progress Telerik