0

我是 wpf 的新手,我希望这是一个简单的问题。

我创建了一个简单的模板来显示一些分组项目

目前,当我单击 ItemsClick 被调用的项目之一时(如预期的那样)

    private void itemGridView_ItemClick(object sender, ItemClickEventArgs e)
    {

        MyCustomClass selectedItem = (MyCustomClass)e.ClickedItem;
        GridView g = (GridView)sender;

我可以通过投射 e.ClickedItem 和来自发件人的网格来获取类对象的副本。但是我没有看到如何获得对我在模板中添加的自定义项目的引用,例如,如果我想更改 testName TextBlock 中的文本?

模板:

<DataTemplate x:Key="MyTestTemplate">
            <Grid HorizontalAlignment="Left"  >
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}" Grid.RowSpan="3">
                    <Image Source="{Binding ThumbnailUrl}" Stretch="Fill" Width="175" Height="175" />
                </Border>
                <Image Source="{Binding MyCustomImage}" Height="30" Width="30" Grid.RowSpan="3" Margin="0,0,0,30"/>
                <Grid x:Name="ItemDetails" VerticalAlignment="Bottom"  Height="75" Margin="0,0,0,2" Background="{StaticResource ListViewItemOverlayBackgroundThemeBrush}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="40"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <TextBlock x:Name="testName" Text="{Binding Name}"  Grid.Row="0" Foreground="{StaticResource ListViewItemOverlayForegroundThemeBrush}" MaxWidth="100" MaxHeight="80" TextWrapping="Wrap" HorizontalAlignment="Left" Style="{StaticResource TitleTextStyle}"  Margin="5,0,5,0"/>
                    <TextBlock Text="{Binding Address}" Grid.Row="0" HorizontalAlignment="Right" Foreground="{StaticResource ListViewItemOverlaySecondaryForegroundThemeBrush}" Style="{StaticResource 

CaptionTextStyle}" TextWrapping="NoWrap" Margin="5,0,5,0" />
                     </Grid>
                </Grid>
            </DataTemplate>


<GridView
            x:Name="itemGridView"
            AutomationProperties.AutomationId="ItemGridView"
            AutomationProperties.Name="Grouped Items"
            Grid.RowSpan="2"
            Padding="116,137,40,46"
            ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
            ItemTemplate="{StaticResource MyTestTemplate}"
            SelectionMode="None"
            IsSwipeEnabled="True"
            IsItemClickEnabled="True" 
            RightTapped="itemGridView_RightTapped" 
            ItemClick="itemGridView_ItemClick" SelectionChanged="itemGridView_SelectionChanged">
            <GridView.ItemsPanel>
                <ItemsPanelTemplate>                        
                    <VirtualizingStackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>
            <GridView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid Margin="1,0,0,6">
                                <Button
                                    AutomationProperties.Name="Group Title"
                                >
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding state}"/>
                                     </StackPanel>
                                </Button>
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,80,0"/>
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </GridView.GroupStyle>
        </GridView>
4

1 回答 1

0

好的,我在 msdn 上找到了答案。

这里的链接http://msdn.microsoft.com/en-us/library/bb613579.aspx

基本步骤

获取所选项目(我正在响应单击,因此此信息很容易),在该项目中找到 ContentPresenter,然后在该 ContentPresenter 上设置的 DataTemplate 上调用 FindName。

于 2013-06-20T20:54:12.267 回答