在metro中跳出窗口有多种形式。我在这里介绍两种情形。第一种是用Popup方法来跳出窗口。主要步骤如下:
首先,打开vs2012找到Blank App模板进去,再拉入一个Button控件,点击事件Click进入。其次,在MainPage.xaml中写入如下代码:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}"> <Button Content="Example 1" Name="btn1" Width="108" Margin="161,96,0,0" VerticalAlignment="Top" Height="52" Click="btn1_Click_1"/> <Popup x:Name="tip1" IsLightDismissEnabled="True" HorizontalOffset="161" VerticalOffset="250"> <Grid Width="312" Height="200"> <Grid.Background> <ImageBrush ImageSource="./mian.png"></ImageBrush> </Grid.Background> <TextBlock Grid.Row="0" Foreground="White" Grid.Column="0" FontSize="15" Height="Auto" HorizontalAlignment="Center" Margin="0 20 0 0" VerticalAlignment="Top"> <Run>春眠不觉晓</Run> <LineBreak/> <LineBreak/> <Run>处处闻啼鸟</Run> <LineBreak/> <LineBreak/> <Run>夜来风雨声</Run> <LineBreak/> <LineBreak/> <Run>花落知多少</Run> </TextBlock> </Grid> </Popup> </Grid>
在click代码中写入:
private void btn1_Click_1(object sender, RoutedEventArgs e) { this.tip1.IsOpen = true; }
这样Popup窗口就可以跳出来了。按F5看是否做好了。
第二种方法就是MessageDialog方法。首先拉近一个Button和TextBlock控件。在Button的事件中,输入以下代码:
private async void Message_Click(object sender, RoutedEventArgs e) { var messageDialog = new MessageDialog("Very good!"); await messageDialog.ShowAsync(); }