Привет Я хотел бы получить доступ к элементам управления внутри файла данных в файле ResourceDictinory.xaml из кода позади.Доступ к элементам внутри таблицы данных в Windows Phone 7
мое содержание ResFile1.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="btnTemplate1">
<StackPanel>
<TextBlock Name="txtBlock" Text="Abcd123" Foreground="Red"/>
<TextBox Name="txtBox" Text="textbox Text"/>
</StackPanel>
</DataTemplate>
ok.I Я использую его, как это в MainPage.xaml
<phone:PhoneApplicationPage.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ResFile1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</phone:PhoneApplicationPage.Resources>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button HorizontalAlignment="Left" Height="152" Margin="106,221,0,0"
VerticalAlignment="Top" Width="256"
ContentTemplate="{Binding ConverterParameter=blabla, Converter={StaticResource TestResConverter}, Mode=OneWay, Source={StaticResource btnTemplate1}}"/>
</Grid>
Мой класс TestResConverter. (Доступ к элементам внутри DataTemplate в этом класс)
public class ConverterTest : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is DataTemplate)
{
DataTemplate dataTemplate = value as DataTemplate;
//access elements
TextBox accessedTextbox = XXXMehod(dataTemplate);
accessedTextbox.Text = (string)parameter;//e.g change text property
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
Как получить доступ к элементам внутри datatemplate? Что такое доступ, редактируя альтернативу DataTemplate? Также я смотрю проекты wpf, но некоторые методы не существуют wp7.
Не существует метода FindName для DataTemplate в wp7.А также, что относится к ItemContainerGenerator? Я не использую ListBoxItem. – Oguzhan