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);
开发者_C百科 }
};
The variable d
is always null.
You can also attached a Loaded event handler, and cast the sender
parameter to DatePicker
精彩评论