简体   繁体   English

在C#中设置按钮图标

[英]Setting a button icon in C#

在此处输入图片说明

Is it possible the change the Icon for btnEdit in my C# code? 是否可以在我的C#代码中更改btnEdit的图标? For example, when you click on btnEdit, the Icon will switch from "Edit" to "Cancel"? 例如,当您单击btnEdit时,图标将从“编辑”切换为“取消”吗?

This app is for Windows Phone 8.1, and I want to use the icons that have already been provided. 该应用程序适用于Windows Phone 8.1,我想使用已经提供的图标。

I have so far been able to switch the label (btnEdit.Label = "Cancel") and this works, but I can't seem to get it working for Icon. 到目前为止,我已经能够切换标签(btnEdit.Label =“ Cancel”)并可以使用,但是我似乎无法使它适用于Icon。

Any suggestions? 有什么建议么?

Try this: 尝试这个:

// Use system provided icon
AppBarButton.Icon = new SymbolIcon(Symbol.Cancel);

// Use custom font icon
AppBarButton.Icon = new FontIcon()
{
    FontFamily = new Windows.UI.Xaml.Media.FontFamily("Your font"),
    Glyph = "glype"
};

您需要将图标设置为Symbol Icon对象而不是字符串

btnEdit.Icon = new SymbolIcon(Symbol.Cancel);

Create two buttons each for Edit and Cancel. 创建两个按钮,分别用于“编辑”和“取消”。 Keep the Edit button visible ad Cancel button hidden. 保持“编辑”按钮可见,而“取消”按钮隐藏。

Edit.Visibility = Visibility.Visible;
Cancel.Visibility = Visibility.Collapsed;

When you click on Edit button reverse the visibility of buttons. 当您单击“编辑”按钮时,反转按钮的可见性。

Edit.Visibility = Visibility.Collapsed;
Cancel.Visibility = Visibility.Visible;

You can assign different icons for each buttons and manage them. 您可以为每个按钮分配不同的图标并进行管理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM