Custom Datafield is not working?

6 posts, 0 answers
  1. Michael
    Michael avatar
    2 posts
    Member since:
    Jan 2017

    Posted 14 Dec 2017 Link to this post

    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

     

  2. Michael
    Michael avatar
    2 posts
    Member since:
    Jan 2017

    Posted 14 Dec 2017 Link to this post

    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

  3. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    908 posts

    Posted 19 Dec 2017 Link to this post

    Hello 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
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  4. rick
    rick avatar
    13 posts
    Member since:
    Jan 2016

    Posted 19 Mar 2018 in reply to Dilyan Traykov Link to this post

    @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:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 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>
  5. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    908 posts

    Posted 20 Mar 2018 Link to this post

    Hello Rick,

    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
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  6. rick
    rick avatar
    13 posts
    Member since:
    Jan 2016

    Posted 20 Mar 2018 in reply to Dilyan Traykov Link to this post

    thanks Dilyan! Work like  a charm!
Back to Top