我将我的两个电话应用程序页面合并在一起。第一个显示当前正在播放的歌曲的图片、标题和艺术家。角落里有一个播放/暂停按钮。
第二个是一个空页面,其中我有一个手势处理程序。在空白页面上,GestureHandler 运行良好。但是,当我将 GestureHandler 带到第一页时,它就不再起作用了。不仅手势处理程序,播放/暂停按钮也不起作用。而且我看不出是什么原因导致 EventHandlers 不工作..
这些是我的 2 个文件:
<phone:PhoneApplicationPage
x:Class="EnergyRadio.ChannelView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:local="clr-namespace:EnergyRadio"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="696" d:DesignWidth="480"
shell:SystemTray.IsVisible="True">
<phone:PhoneApplicationPage.Resources>
<Style x:Key="CustomButtonStyle" TargetType="Button">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/>
<Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/>
<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Background="Transparent">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver"/>
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneBackgroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneForegroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneForegroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="0" Margin="0">
<ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</phone:PhoneApplicationPage.Resources>
<!--LayoutRoot ist das Stammraster, in dem alle anderen Seiteninhalte platziert werden-->
<Grid Margin="0" x:Name="LayoutRoot" Background="Transparent" VerticalAlignment="Top" IsHitTestVisible="False">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel enthält den Namen der Anwendung und den Seitentitel-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="0" Orientation="Vertical" Opacity="1" HorizontalAlignment="Right" VerticalAlignment="Top">
<!--<TextBlock x:Name="ApplicationTitle" Text="ENERGY RADIO" Style="{StaticResource PhoneTextNormalStyle}"/>-->
<Image Margin="0,0,0,0" Source="/EnergyRadio;component/img/subpage_header.jpg" />
<Grid Grid.Row="1" Margin="24,0,24,0" HorizontalAlignment="Left">
<!-- <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>-->
<Image Name="channellogo" Margin="0,0,192,0" Width="240" Height="76" />
<Button Style="{StaticResource CustomButtonStyle}" Width="64" Height="64" Padding="0" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="368,0,0,0" HorizontalContentAlignment="Left" BorderThickness="0">
<Button.Background>
<ImageBrush ImageSource="/EnergyRadio;component/img/WP7_Pause.png" Stretch="None" />
</Button.Background>
</Button>
</Grid>
</StackPanel>
<!--ContentPanel - zusätzliche Inhalte hier platzieren-->
<phone:WebBrowser Name="wemfBrowser" Width="0" Height="0" Source="" />
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="24,24,24,0">
<Rectangle Height="600" Width="450">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener Flick="GestureListener_Flick" />
</toolkit:GestureService.GestureListener>
</Rectangle>
<Image Height="432" HorizontalAlignment="Left" Margin="0,0,0,0" Name="cover" Stretch="Fill" VerticalAlignment="Top" Width="432" />
<TextBlock Margin="0,432,0,0" Height="30" Name="artist" Text="Artist" VerticalAlignment="Top" HorizontalAlignment="Left" />
<TextBlock Margin="0,456,0,0" Height="30" Name="title" Text="Title" VerticalAlignment="Bottom" HorizontalAlignment="Left" />
</Grid>
</Grid>
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True" Mode="Minimized" Opacity="1.0" >
<shell:ApplicationBarIconButton IconUri="/Images/save.png" Text="Get Ringtone" Click="getRingtone_Click" />
<shell:ApplicationBarIconButton IconUri="/Images/delete.png" Text="Add Shortcut" Click="addShortcut_Click" />
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
我的第二个文件(空页面和手势处理程序:):
<phone:PhoneApplicationPage
x:Class="EnergyRadio.RemoteView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:local="clr-namespace:EnergyRadio"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot ist das Stammraster, in dem alle anderen Seiteninhalte platziert werden-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel enthält den Namen der Anwendung und den Seitentitel-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="Energy Radio" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="Remote" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - zusätzliche Inhalte hier platzieren-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Rectangle Height="600" Width="450" Fill="White">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener Flick="GestureListener_Flick" />
</toolkit:GestureService.GestureListener>
</Rectangle>
</Grid>
</Grid>
<!--Beispielcode zur Verwendung von ApplicationBar-->
<!--<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Schaltfläche 1"/>
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Schaltfläche 2"/>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="Menüelement 1"/>
<shell:ApplicationBarMenuItem Text="Menüelement 2"/>
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>-->
编辑:
好的,我发现我需要给 Rectangle 属性 FILL="white" 才能让手势处理程序工作。
但是 Rectangle 必须在前面,所以我可以在屏幕上的任何地方使用 GestureHandler 并且它必须是透明的。
所以有人知道我如何使矩形透明但仍然“可点击”?如果我只是删除 Fill="white" 它不起作用。