完整的DataTemplate可点击?

时间:2014-05-07 06:36:13

标签: c# xaml windows-phone-8 mvvm

我在XAML视图中的phone.LongListSelector中使用了DataTemplate:

    <DataTemplate x:Name="myLocationsListTemplate">
        <StackPanel Margin="0,0,0,15">
            <Grid VerticalAlignment="Top" Margin="0,0,5,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="120" />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" TextTrimming="WordEllipsis" Text="{Binding Name}" TextWrapping="NoWrap" Style="{StaticResource PhoneTextLargeStyle}" VerticalAlignment="Top" Margin="0,0,0,22" />
                <Image Grid.Column="0" Width="138" Height="25" Source="/mAppData/stars-3.png" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="0"/>
                <TextBlock Grid.Column="1" Text="{Binding DistanceInMeterFormatted, FallbackValue=fallback, TargetNullValue=nullvalue, Mode=OneWay}" TextWrapping="NoWrap" Style="{StaticResource PhoneTextSubtleStyle}" HorizontalAlignment="Right" Margin="0,0,-3,20" VerticalAlignment="Bottom"/>
                <TextBlock Grid.Column="1" Text="vor 10 min." TextWrapping="NoWrap" Margin="0" Style="{StaticResource PhoneTextSubtleStyle}" HorizontalAlignment="Right" VerticalAlignment="Bottom"/>
            </Grid>
            <Grid VerticalAlignment="Top" Margin="0,10,0,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Image Grid.Column="0" Width="100" Height="100" Source="{Binding PreviewImg1}"/>
                <Image Grid.Column="1" Width="100" Height="100" Source="{Binding PreviewImg2}"/>
                <Image Grid.Column="2" Width="100" Height="100" Source="{Binding PreviewImg3}"/>
                <Image Grid.Column="3" Width="100" Height="100" Source="{Binding PreviewImg4}"/>
            </Grid>
        </StackPanel>
    </DataTemplate>

现在我想要制作完整的DataTemplate内容&#34;可点击&#34;。意思是:如果用户点击TextBlock或四个图像中的一个或者在List List中显示的内容,则应该使用数据绑定属性执行操作(应该给出绑定数据中的Name)。

任何想法如何使这个工作?

1 个答案:

答案 0 :(得分:1)

为什么不把整个模板都粘在按钮上?如果需要删除任何您不喜欢的默认外观,您可以设置按钮的样式。例如。

<Style x:Key="BlankButtonStyle" TargetType="ButtonBase">

    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ButtonBase">
                <ContentPresenter />
            </ControlTemplate>
        </Setter.Value>
    </Setter>

    <Setter Property="Background" Value="Transparent" />
</Style>