2015-12-18 34 views
0

我有簡單的應用程序的Windows 8.1(C#)。它有一個頁面,我想以編程方式添加標準圖像按鈕「設置」。 是否可以爲按鈕使用標準靜態圖像資源?Windows 8.1應用程序。圖像按鈕「設置」

Button btnSettings = new Button(); 
btnSettings.Height = 50; // will be as image size 
btnSettings.Width = 50; 
//btnSettings.Content = "TEST"; 
Canvas.Children.Add(btnSettings); // I have big Canvas object 
btnSettings.UpdateLayout(); 
Canvas.SetTop(btnSettings, 0); 
Canvas.SetLeft(btnSettings, dx - btnSettings.ActualWidth); // dx - canvas width 
//btnSettings.Style = ??? 

謝謝。

回答

0

我按鈕你可以用它的源 指定子圖像從ContentControl中:https://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj153346.aspx#Y778

所以只是一個孩子圖像控件添加到該按鈕,並設置其來源。這是向你展示的xaml方法 - 但你可以在代碼中執行此操作。

 
<Button Click="Button_Click_1" 
     Background="#FF0D6AA3" 
     Height="100" Width="100" > 
    <StackPanel> 
     <Image Source="Assets/Banana.png"/> 
     <TextBlock Text="Banana" HorizontalAlignment="Center"/> 
    </StackPanel> 
</Button> 

設置圖像源如下:

 
Image img = new Image(); 
img.Source = new BitmapImage(new Uri("ms-appx:///Assets/Logo.png")); 
0

確定。這是錯誤的方式。 要創建設置頁面,請使用此link。 因此,用戶可以通過將鼠標光標移至右上方或下方屏幕核心器並選擇「設置」菜單項來調用系統窗格。 在窗格中,用戶可以點擊鏈接「MySettings」。

相關問題