我有這樣的XAML。 (此代碼是我的源代碼只是一些部分)訪問DataTemplate中的TextBox
<UserControl x:Class="EmployeeClass"
...............>
.............
.............
<ListView x:Name="EmployeeList" Width="700" Height="500" Margin="10"
ItemsSource ="{Binding Source={x:Static local:Company.employeeList}}"
Background="Black"
ItemTemplateSelector="{DynamicResource myDataTemplateSelector}" Focusable="False"
IsSynchronizedWithCurrentItem="True">
</ListView>
</UserControl>
這裏是我的數據模板的一個
<DataTemplate x:Key="SeniorEmployee" DataType="{x:Type local:ListEmployee}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="10">
<Image x:Name="ProfilePicture" Source="{Binding Path=ProfilePict}" Stretch="Fill" Width="80" Height="80" VerticalAlignment="Top"></Image>
<StackPanel Orientation="Vertical" Margin="5">
<TextBlock Text="{Binding Path=Attribution}" Foreground="White" TextWrapping="Wrap" Width="400" VerticalAlignment="Top" HorizontalAlignment="Left"/>
<StackPanel Margin="7,5,0,7">
<UISkripsi3:CommandTextBox Name="AttributionTextBox" HorizontalAlignment="Left" Margin="10,5" Panel.ZIndex="1"
BannerText="Add to the attribution" FontSize="{DynamicResource LargeFontSize1}"
SpellCheck.IsEnabled="True" Style="{DynamicResource AttributionTextBoxStyle}"
TextWrapping="Wrap">
</UISkripsi3:CommandTextBox>
<Button Style="{DynamicResource StandardButtonStyle}" IsEnabled="{Binding ElementName=AttributionTextBox, Path=Text, Converter={StaticResource IsStringNullOrWhitespaceConverter}, ConverterParameter=Inverse}" Click="AttributionButtonClick" Height="22" HorizontalAlignment="Right" Margin="10,4,10,0" Panel.ZIndex="0" CommandTarget="{Binding ElementName=AttributionTextBox}" Content="Show" FontSize="{DynamicResource LargeFontSize1}">
</Button>
</StackPanel>
</Grid>
</DataTemplate>
如果用戶類型的東西在AttributionTextBox並單擊按鈕,會出現一個消息顯示用戶輸入的文字。我曾嘗試 http://blogs.msdn.com/b/wpfsdk/archive/2007/04/16/how-do-i-programmatically-interact-with-template-generated-elements-part-ii.aspx 和H * TP視覺樹幫手://msdn.microsoft.com/en-us/library/system.windows.media.visualtreehelper.aspx
我的問題是,我可以」 t在代碼後面找到AttributionTextBox。我也無法訪問EmployeeList Listview,因爲它不是在後面的代碼中生成的。任何人都可以幫我解決這個問題嗎?
我想訪問AttributionTextBox而不是Attribution屬性,當用戶輸入一些內容並點擊按鈕時,文本將被顯示。但是,thx爲您的建議 – 2010-09-06 13:52:29