This is a migrated thread and some comments may be shown as answers.

DataFormDataField.ContentTemplate example

5 Answers 365 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 01 Mar 2013, 04:38 PM

I am using Telerik WPF Q3 2012.

I am following the example in http://www.telerik.com/help/wpf/raddataform-customized-fields.html

Since I can only upload images, I am including the text of MainWindow here (see below).

Summary;

  • When I use the standard DataFormDataField with Label and DataMemberBinding, things are good (I can see data and it is read only until I click Edit).
  • When I use the DataFormDataField.ContentTemplate as per the example, I see a blank label and blank text field. I can not change the data
  • When I tried DataFormDataField.Content, I can see the data but it is always writable (even before I click the edit button).

I would like to get the DataFormDataField.ContentTemplate working so I can create the field layout that I want. I think I am missing something.

Please help

Thank you
Mark

------------MainWindow.xaml.cs ----------------

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Example
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            MyDataForm.ItemsSource = GetData();
        }
        private ObservableCollection<TestData> GetData()
        {
            ObservableCollection<TestData> result = new ObservableCollection<TestData>();

            TestData a = new TestData()
            {
                Name = "Hello",
                Remark = "Where are you?",
                Comment = "Bye"
            };

            result.Add(a);
            return result;
        }

        private void MyDataForm_EditEnded_1(object sender, Telerik.Windows.Controls.Data.DataForm.EditEndedEventArgs e)
        {
            TestData a = MyDataForm.CurrentItem as TestData;
            // Notice that a.Remark is not changed event if you edit data in the remarks field
        }
    }
    public class TestData
    {
        public String Name { get; set; }
        public String Remark{ get; set; }
        public String Comment { get; set; }
    }
}

----------------- MainWindow.xaml ---------------

 

<Window x:Class="Example.MainWindow"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.Resources>
            <DataTemplate x:Key="MyDataTemplate">
                <StackPanel>
                   
                    <!-- Basic definition -->
                    <telerik:DataFormDataField Label="Name" DataMemberBinding="{Binding Name}" ToolTip="Basic Layout" />
                   
                    <!-- Based on Custom Fields example, but nothing is displayed -->
                    <telerik:DataFormDataField ToolTip="Nothing is displayed"  >
                        <telerik:DataFormDataField.ContentTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Vertical">
                                    <TextBox Text="Remarks"  Background="Green"/>
                                    <TextBox Text="{Binding Remarks, Mode=TwoWay}" />
                                </StackPanel>                               
                            </DataTemplate>
                        </telerik:DataFormDataField.ContentTemplate>
                    </telerik:DataFormDataField>
                   
                    <!-- Another Attempt, but it is readable before click Edit button -->
                    <telerik:DataFormDataField Label="Comment" ToolTip="Always Editable" >
                        <telerik:DataFormDataField.Content>
                            <TextBox Text="{Binding Comment, Mode=TwoWay}" />
                        </telerik:DataFormDataField.Content>
                    </telerik:DataFormDataField>

                </StackPanel>
            </DataTemplate>
        </Grid.Resources>

        <!-- Metadata information -->
        <telerik:RadDataForm x:Name="MyDataForm"
                             AutoGenerateFields="False"
                             ReadOnlyTemplate="{StaticResource MyDataTemplate}"
                             EditTemplate="{StaticResource MyDataTemplate}"
                             CommandButtonsVisibility="Edit,Commit, Cancel"
                             EditEnded="MyDataForm_EditEnded_1">
        </telerik:RadDataForm>

    </Grid>
</Window>

 

5 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 06 Mar 2013, 04:42 PM
Hi,

 There is a little difference with this behavior between WPF and Silverlight. In WPF you should use Content. However, we have internal logic that binds the inner control's IsEnabled/IsReadOnly property to its parent field's IsReadOnly property, so that both ReadOnly and Edit modes could be supported. Just add such a binding and you will achieve the desired results.

All the best,
Ivan Ivanov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Mark
Top achievements
Rank 1
answered on 06 Mar 2013, 05:29 PM
1) Please supply to correct XAML for this specific example.

2) Also please update your example in http://www.telerik.com/help/wpf/raddataform-customized-fields.html

0
Ivan Ivanov
Telerik team
answered on 12 Mar 2013, 01:33 AM
Hello,

 Well, I have managed to make it work with ContentTemplate. May I ask you to test the attached project on your side and tell us about any notable differences. Meanwhile we will investigate similar scenarios further.

All the best,
Ivan Ivanov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Mark
Top achievements
Rank 1
answered on 12 Mar 2013, 07:53 PM
Oh no,

Ivan, I am sorry that you did extra work. I did not intend for you to "make it work" with control templates. I only wanted the current WPF example updated to show what you meant by "Just add such a binding and you will achieve the desired results." 

I guess it is something like:
 IsReadOnly={Binding RelativeSource={RelativeSource AncestorType=telerik:DataFormDataField}, Path=IsReadOnly }

I put that in my code and it seems to work for me. But I am not sure it is what you meant.

I only want the Telerik example updated so it clear for others who will use the example.

Please see http://www.telerik.com/account/support-tickets/view-ticket.aspx?threadid=666762 for more context.








0
Accepted
Ivan Ivanov
Telerik team
answered on 18 Mar 2013, 07:28 AM
Hello,

 Actually this is exactly what I have done in my example - a relative source binding to the field itself. As for the examples in the support articles. We will revise both the WPF and the SL one, so that we are sure that everything works as expected. 

All the best,
Ivan Ivanov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
DataForm
Asked by
Mark
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Mark
Top achievements
Rank 1
Share this question
or