Windows phone 8 如何在点击图像时显示画布

Windows phone 8 如何在点击图像时显示画布,windows-phone-8,Windows Phone 8,我在app.xaml中定义了datatemplate 我有一张照片 在我的自定义页面中,我有一个画布 如何在点击图像时显示此画布? 这是我在app.xaml中的数据模板 <DataTemplate x:Key="FlightInfoDataTemplate"> <Grid HorizontalAlignment="Stretch" Width="420"> <Grid.ColumnDefinitions>

我在app.xaml中定义了datatemplate 我有一张照片 在我的自定义页面中,我有一个画布 如何在点击图像时显示此画布? 这是我在app.xaml中的数据模板

<DataTemplate x:Key="FlightInfoDataTemplate">
            <Grid HorizontalAlignment="Stretch" Width="420">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto"/>
                </Grid.ColumnDefinitions>
               <!-- here are controls, which are not necessary now-->
                    <Image Tag="{Binding ID}" Source="/Images/bel_icon_2.png" Width="20" Height="20" Visibility="{Binding Path=Status, Converter={StaticResource StatusToVisibilityConverter}}" />
                <!--***********-->
            </Grid>
        </DataTemplate>
这是我在MainPage.xaml中定义的画布

<Canvas x:Name="AddReminderDialog" HorizontalAlignment="Center"  Height="280" Width="260"
                VerticalAlignment="Center" Background="Transparent" Margin="110,178,110,238" Visibility="Collapsed">
            <TextBlock Foreground="Yellow" Text="Напомнить" HorizontalAlignment="Center" Canvas.Left="78" Canvas.Top="28" />
            <Button Name="btn1HourBef" BorderThickness="0" Background="Black" Content="За час" Width="260" FontSize="15" Height="60" Margin="0,70,0,0"/>
            <Button Name="btn30MinBef" BorderThickness="0" Background="Black" Content="За 30 минут" Width="260" FontSize="15" Height="60" Margin="0,130,0,0"/>
            <Button Name="btn10MinBef" BorderThickness="0" Background="Black" Content="По прилету/вылету" Width="260" FontSize="15" Height="60" Margin="0,190,0,0"/>
        </Canvas>
如何在点击图像时使其可见?

编辑-画布用于通知,最好可在多个页面上重复使用:

根据评论,画布的意图显然是提供通知消息。适合于可驳回弹出窗口概念的东西。框架中已存在System.Windows.Controls.Primitives.Popup类

例如: 在App.xaml中:

<DataTemplate x:Key="FlightInfoDataTemplate">
...
<Image Tag="{Binding ID}" Source="/Images/bel_icon_2.png" Width="20" Height="20" Visibility="{Binding Path=Status, Converter={StaticResource StatusToVisibilityConverter}}" Tap="Image_Tap"/>
...
</DataTemplate>

<ControlTemplate x:Key="AddReminderDialog">
    <Canvas HorizontalAlignment="Center"  Height="280" Width="260" VerticalAlignment="Center" Background="WhiteSmoke" Margin="110,178,110,238">
        <TextBlock Foreground="Black" Text="Hello" HorizontalAlignment="Center" Canvas.Left="78" Canvas.Top="28" />
        <Button Name="btn1HourBef" BorderThickness="0" Background="Black" Content="За час" Width="260" FontSize="15" Height="60" Margin="0,70,0,0"/>
        <Button Name="btn30MinBef" BorderThickness="0" Background="Black" Content="За 30 минут" Width="260" FontSize="15" Height="60" Margin="0,130,0,0"/>
        <Button Name="btn10MinBef" BorderThickness="0" Background="Black" Content="По прилету/вылету" Width="260" FontSize="15" Height="60" Margin="0,190,0,0"/>
    </Canvas>
</ControlTemplate>

但是我的addEmlerderDialog是在MainPage.xaml上定义的。datatemplate位于App.xaml中的resources@Umriyaev对不起,我误解了这个问题。我将使用正确的信息进行更新。我会在mainpage.xaml中定义该数据模板,但该模板在多个页面中使用,因此,我认为最好在应用程序资源中定义它。我还想在应用程序资源中定义画布,但当您将弹出窗口的可见性更改为可见时,它将仅在定义它的页面上可见。这就是为什么我在主页和其他使用datatemplate的页面中定义了canvas。我的应用程序的主要目的是显示航班信息。目前,我在单独的页面中显示有关本地和全球航班的信息。除此之外,我还有到达和离开的类别。总而言之,我有4页,显示航班信息:本地到达、本地起飞、全球到达和全球起飞。这就是我决定在应用程序资源中创建公共数据模板的原因。现在,我想添加通知功能。这就是为什么我需要乌姆里亚耶夫,我明白了。你的问题没有提到任何弹出窗口。在这种情况下,您可以使用Popup类。我可以举个例子。
public partial class App : Application
{
    private Popup popup = new Popup();
...

private void Image_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
    var image = sender as Image;
    var modelItem = image.DataContext;

    const double width = 200;
    const double height = 100;

    var content = new ContentControl(){Width = width, Height = height, Background = new SolidColorBrush(Colors.Purple)};
    content.Template = (ControlTemplate) Resources["AddReminderDialog"];
    content.DataContext = modelItem; // you should define bindings in the ControlTemplate.

    popup.Child = content;
    popup.Height = height;
    popup.Width = width;
    popup.VerticalOffset = Application.Current.RootVisual.RenderSize.Height / 2 - height / 2;
    popup.HorizontalOffset = Application.Current.RootVisual.RenderSize.Width / 2 - width / 2;
    popup.IsOpen = true;
}