2015-12-18 30 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”。

相关问题