Windows 8技巧:Xaml+C#開發(fā)第一個(gè)Metro Style應(yīng)用程序的使用

然后我們打開VS2012,選擇Windows Metro Style,然后選擇創(chuàng)建Blank App項(xiàng)目如下圖:

其新建完成的項(xiàng)目結(jié)構(gòu)如下:
我們拖動(dòng)一個(gè)按鈕和ListBox到界面中,設(shè)置按鈕事件以及ListBox的DataTemplate,如下Xaml代碼:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Button Content="Button" Name="button1" HorizontalAlignment="Left"
Margin="135,124,0,0" VerticalAlignment="Top" Click="button1_Click"/>
<ListBox HorizontalAlignment="Left" Name="listbox1" Height="100"
Margin="135,187,0,0" VerticalAlignment="Top" Width="140">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Width="60" Text="{Binding ItemName}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
其Xaml.cs文件如下:
/// <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();
listbox1.ItemsSource = ItemModel.GetItem();
button1.Content = "Windows 8按鈕";
}</p> <p> /// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}</p> <p> private void button1_Click(object sender, RoutedEventArgs e)
{
this.button1.Content = this.button1.Content + "1";
}
}
ListBox綁定的數(shù)據(jù)源代碼如下:
public class ItemModel
{
public string ItemName { get; set; }</p> <p> public string ItemValue { get; set; }</p> <p> public static List<ItemModel> GetItem()
{
List<ItemModel> list = new List<ItemModel>();
list.Add(new ItemModel() { ItemName = "北京", ItemValue = "010" });
list.Add(new ItemModel() { ItemName = "上海", ItemValue = "020" });
list.Add(new ItemModel() { ItemName = "成都", ItemValue = "028" });
return list;
}
}
運(yùn)行效果圖如下:
相關(guān)文章
Win8.1 KB5021294補(bǔ)丁月度更新匯總!(附完整更新日志)
微軟已向用戶發(fā)布了Win8.1月度更新匯總,補(bǔ)丁為KB5021294,下文為大家?guī)砹嗽敿?xì)的更新介紹,需要的朋友一起看看吧2022-12-15微軟警告:Win8.1系統(tǒng)即將停止支持,將很快彈窗提醒,建議購買 Win11/1
6月24日消息,據(jù)報(bào)道,微軟正準(zhǔn)備開展行動(dòng),通知Windows8.1用戶關(guān)于該產(chǎn)品的停止支持日期,下面隨小編一起來看看吧2022-06-24win8系統(tǒng)怎么加密文件?win8系統(tǒng)加密文件詳細(xì)操作方法
這篇文章主要介紹了win8系統(tǒng)怎么加密文件?win8系統(tǒng)加密文件詳細(xì)操作方法的相關(guān)資料,需要的朋友可以參考下本文詳細(xì)內(nèi)容介紹2022-06-13win8系統(tǒng)如何設(shè)置開機(jī)密碼?Win8系統(tǒng)設(shè)置開機(jī)密碼操作教程
這篇文章主要介紹了win8系統(tǒng)如何設(shè)置開機(jī)密碼?Win8系統(tǒng)設(shè)置開機(jī)密碼操作教程的相關(guān)資料,需要的朋友可以參考下本文詳細(xì)內(nèi)容介紹2022-06-13Win8系統(tǒng)在后臺(tái)運(yùn)行打印機(jī)程序操作教程
這篇文章主要介紹了Win8系統(tǒng)在后臺(tái)運(yùn)行打印機(jī)程序操作教程的相關(guān)資料,需要的朋友可以參考下本文詳細(xì)內(nèi)容介紹2022-06-13Win8系統(tǒng)安全證書過期怎么辦?Win8系統(tǒng)安全證書過期的解決方法
這篇文章主要介紹了Win8系統(tǒng)安全證書過期怎么辦?Win8系統(tǒng)安全證書過期的解決方法的相關(guān)資料,需要的朋友可以參考下本文詳細(xì)內(nèi)容介紹2022-06-13win8系統(tǒng)還原怎么操作呢?win8電腦系統(tǒng)還原詳細(xì)步驟
如何解決Win10瀏覽器打不開網(wǎng)頁但能上網(wǎng)?最近很多用戶向小編反應(yīng)升級(jí)了win10系統(tǒng)之后在下載軟件或者打開第三方網(wǎng)頁的時(shí)候會(huì)出現(xiàn)病毒誤報(bào),該怎么辦呢?跟隨小編來看看吧2020-12-31- Win8臨時(shí)文件夾如何修改路徑?Win8臨時(shí)文件夾文件過多會(huì)影響速度,我們可以通過修改文件路徑很好的解決這一問題,下面讓我們來看看如何修改2020-12-22
Win8系統(tǒng)如何設(shè)置鼠標(biāo)左右鍵互換?
Win8系統(tǒng)如何設(shè)置鼠標(biāo)左右鍵互換?最近很多小伙伴向小編咨詢關(guān)于Win8系統(tǒng)設(shè)置鼠標(biāo)左右鍵互換的問題,下面就跟隨小編一起學(xué)習(xí)吧2020-12-11Win8系統(tǒng)怎么關(guān)閉系統(tǒng)還原?
Win8系統(tǒng)怎么關(guān)閉系統(tǒng)還原?最近很多win8系統(tǒng)的用戶向小編咨詢想要關(guān)閉系統(tǒng)還原,不知道如何操作,不妨我們一起來看看下文的教程吧2020-12-09