Is it possible to add a DataField to a Silverlight DataForm without creating an entire editing template?

I am using a DataForm for an object with 40 attributes. I am pleased with the way the form displays all but 3 attributes. These 3 attributes are item lists.

I do not want to code the entire editing template, it seems to be very effective.

<dataFormToolkit:DataForm AutoGenerateFields="True" CurrentItem="{Binding XXX, Mode=TwoWay, Source={StaticResource XXXViewModel}}" >
                    <dataFormToolkit:DataField Label="Client"  >
                        <ListBox ItemsSource="{Binding Client}"></ListBox>
                    </dataFormToolkit:DataField>
                </dataFormToolkit:DataForm>
+3
source share
3 answers

WCF RIA Services Silverlight Business Application, CustomDataForm, OnAutoGeneratingField , . , , , , ReplaceTextBox, . .

public class CustomDataForm : DataForm
{
    protected override void OnAutoGeneratingField(DataFormAutoGeneratingFieldEventArgs e)
    {
        // Get metadata about the property being defined
        PropertyInfo propertyInfo = this.CurrentItem.GetType().GetProperty(e.PropertyName);

        // Do the password field replacement if that is the case
        if (e.Field.Content is TextBox && this.IsPasswordProperty(propertyInfo))
        {
            e.Field.ReplaceTextBox(new PasswordBox(), PasswordBox.PasswordProperty);
        }

        // Keep this newly generated field accessible through the Fields property
        this.fields[e.PropertyName] = e.Field;

        // Call base implementation (which will call other event listeners)
        base.OnAutoGeneratingField(e);
    }
}
+5

:

    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)]
    public class IsPassword : System.Attribute { }

  public class CustomDataForm : DataForm
    {
        protected override void OnAutoGeneratingField(DataFormAutoGeneratingFieldEventArgs e)
        {
            // Get metadata about the property being defined
            PropertyInfo propertyInfo = this.CurrentItem.GetType().GetProperty(e.PropertyName);

            // Do the password field replacement if that is the case
            var attributes = propertyInfo.GetCustomAttributes(typeof(IsPassword), false).ToList();

            if (attributes.Any(obj=>obj is IsPassword))
            {
                PasswordBox box= new PasswordBox();
                Binding binding = new Binding(e.PropertyName);
                binding.Mode = BindingMode.TwoWay;
                box.SetBinding(PasswordBox.PasswordProperty, binding);
                e.Field.Content=box;            
            }
            base.OnAutoGeneratingField(e);
        }
    }

[]

+1

, . , .

, , - viewmodel , 37 , . 3, . , : . , , . , , .

-1

Source: https://habr.com/ru/post/1727913/


All Articles