开发者

Silverlight: Access element in DataForm EditTemplate by name [duplicate]

This question already has answers here: How can I find WPF controls by name or type? (21 answers) Closed 2 years ago.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜