开发者

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

开发者 https://www.devze.com 2023-03-17 00:23 出处:网络
This question already has answers here: How can I find WPF controls by name or type? (21 answers) Closed 2 years ago.
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

精彩评论

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