WPF 功能区按钮
如何以编程方式设置 RibbonButton 上的文本?现在我有下面的代码,但按钮不显示“浏览”。有什么建议吗?
RibbonButton btn = new RibbonButton();
btn.Name = "btnBrowse";
btn.Content = "Browse";
btn.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
btn.Click += new RoutedEventHandler(btn_Click);
How can I programatically set the text on a RibbonButton? Right now I have the code below, but the button does not display 'Browse'. Any suggestions?
RibbonButton btn = new RibbonButton();
btn.Name = "btnBrowse";
btn.Content = "Browse";
btn.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
btn.Click += new RoutedEventHandler(btn_Click);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
RibbonControlsLibrary 中的 RibbonButton 的行为与标准 WPF 按钮不同,并且需要命令来显示文本。您还可以在该命令中分配图像和其他项目(例如工具提示)。
您必须为 CanExecute 指定 true,否则命令/按钮将始终被禁用。 CanExecute 方法还可以让您的业务逻辑禁用或启用命令/按钮。
RibbonButtons from the RibbonControlsLibrary behave differently than standard WPF buttons and need a command to display text. The command is where you also assign the images and other items such as tool tips.
You must assign true to CanExecute, otherwise will the command/button will always be disabled. The CanExecute method can have your business logic disable or enable the command/button as well.
WPF 按钮是与 WPF 中的其他所有内容一样的容器。创建一个 TextBlock 并将其设置为按钮的内容:
也就是说,我强烈建议您考虑在 XAML 中构建 UI。如果文本在运行时会发生变化,请对按钮的文本进行数据绑定。
WPF Buttons are containers like just about everything else in WPF. Create a TextBlock and set it as the Content of your button:
That said, I hightly suggest you consider building your UI in XAML. If the text will change during runtime, databind the text of the button.