WP7入门1

  • 按钮Click事件:
private void myButton1_Click(object sender, RoutedEventArgs e)
        {
            string str = "go to your c\\ ";
            myTextBlock.Text = str;
        }
红色部分为该组件的属性name的名称。在这里我们有:
 <Button Content="myTextButton" Name="myButton" VerticalAlignment="Top" Width="160" ClickMode="Press" Click="myButton_Click" />
 <TextBlock Height="210" HorizontalAlignment="Left" Margin="6,226,0,0" Name="myTextBlock" Text="" VerticalAlignment="Top" Width="450" FontSize="32" Clip="{Binding}" />
除了这些你还需要指定该Button的Click方法



  • 在项目中显示图片
在xaml文件中导入一个Image并指定它的的Source。(Source:要现实的图片的URI)


/StringFormats;component/Images/Koala.jpg:这个是该图片的URI
现在我们可以通过点击事件修改Image的图片,换一张显示出来。这时候我们可以在click方法中使用
               BitmapImage img = new BitmapImage(new Uri("/StringFormats;component/Images/Penguins.jpg", UriKind.Relative));
               image.Source = img;
来实现该功能。其中image为Image的名称,跟上面的Button和TextBlock一样。

  • 拖动图片
     通过使用ScrollViewer我们可以把一个大尺寸图片拖动显示,下面为代码
            <ScrollViewer Margin="30,30,30,30" HorizontalScrollBarVisibility="Visible">
                      <Image Height="800" HorizontalAlignment="Left" Name="image" Stretch="Uniform" VerticalAlignment="Top" Width="800"        
                        Source="/StringFormats;component/Images/Koala.jpg" />
            </ScrollViewer>
     当Image的大小超出屏幕的尺寸时,我们可以使用该方法浏览图片


posted @ 2012-01-08 15:56  卡马克  阅读(532)  评论(1编辑  收藏  举报