03 March 2017

Windows Store và Page: Hiện thị Images trên Windows Store Apps

Yêu cầu: Windows 10 và Visual Studio 2015
- Có 3 cách hiển thị Images
- Hiển thị thông thường
1.<Image x:Name="image1" Source="Assets/thaicreate-logo.jpg"
Margin="37,29,1102,569"/>
- Hiển thị với local Resource
1.<Image x:Name="image2" Margin="37,29,1102,569"/>
1.Uri uri = new Uri(BaseUri, "images/Net.png");
2.BitmapImage imgSource = new BitmapImage(uri);
3.this.image2.Source = imgSource;
- Hiển thị với Web Resource
1.<Image x:Name="image3" Margin="37,29,1102,569"/>
2.BitmapImage bm = new BitmapImage(new Uri(url, UriKind.Absolute));
3.this.image3.Source = bm;
- Tạo project App1
- Tạo foder mới tên images
- Coppy ảnh vào foder images


MainPage.xaml
Windows Store 2017
<Page
    x:Class="App1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Image x:Name="image1" Source="images/Net.png" HorizontalAlignment="Left" Height="200" Margin="210,140,0,0" VerticalAlignment="Top" Width="200"/>
        <Image x:Name="image2" HorizontalAlignment="Left" Height="200" Margin="510,140,0,0" VerticalAlignment="Top" Width="200"/>
        <Image x:Name="image3" HorizontalAlignment="Left" Height="200" Margin="810,140,0,0" VerticalAlignment="Top" Width="200"/>
    </Grid>
</Page>
MainPage.xaml.cs
Windows Store 2017
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace App1
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {

            // Image 2 (Local resource)
            Uri uri = new Uri(BaseUri, "images/Firefox.png");
            BitmapImage imgSource = new BitmapImage(uri);
            this.image2.Source = imgSource;

            // Image 3 (Web resource)
            string url = "https://s10.postimg.org/qi7r4wdux/Chrom.png";
            BitmapImage bm = new BitmapImage(new Uri(url, UriKind.Absolute));
            this.image3.Source = bm;

        }
    }
}
- Chạy chương trình

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang