Доступ к TextBox в DataTemplate - PullRequest
       0

Доступ к TextBox в DataTemplate

1 голос
/ 05 сентября 2010

У меня такой XAML.(Этот код является лишь частью моего исходного кода)

<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

Моя проблема в том, что я не могу найти AttributionTextBox в коде позади.Я также не могу получить доступ к списку EmployeeList, потому что он не был сгенерирован в коде.Может кто-нибудь помочь мне решить проблему?

1 Ответ

0 голосов
/ 05 сентября 2010

Как насчет установки режима Binding to TwoWay и доступа к свойству Attribution вместо этого? Это кажется намного проще, чем ходить по визуальному дереву.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...