1

How does one access a control in a DataForm's EditTemplate from the code behind?

The following EditTemplate applies:

<toolkit:DataForm ItemsSource="{Binding ElementName=someDomainDataSource, Path=Data, Mode=TwoWay}">
    <toolkit:DataForm.EditTemplate>
        <DataTemplate>
            <StackPanel>
            ....
            <sdk:DatePicker DisplayDate="{Binding DueDate, Mode=TwoWay}}" 
                            x:Name="dpCustomMaterialDueDate"/>
        ....
            </StackPanel>
        </DataTemplate>
        </toolkit:DataForm.EditTemplate>
</toolkit:DataForm>

Is it possible to access the DatePicker from the code-behind file using the variable name dpCustomMaterialDueDate? Intellisense seems unable to find it.

Also tried to access it in the DataForm's ContentLoaded event, but no luck, i.e.

dataformPrintOrders.ContentLoaded += (sender, args) =>
            {
                DatePicker d = (DatePicker) 
                   dataformPrintOrders.FindNameInContent("dpCustomMaterialDuedate");
                if (d != null)
                {
                    d.DisplayDateStart = DateTime.Now.AddMonths(-1);
                    d.DisplayDateEnd = DateTime.Now.AddMonths(12);
                }
            };

The variable d is always null.

Ryan
  • 26,884
  • 9
  • 56
  • 83

1 Answers1

0

You can also attached a Loaded event handler, and cast the sender parameter to DatePicker

Adriaan Davel
  • 710
  • 1
  • 11
  • 25