- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的问题基本上是this one 。不过,我认为提供更多信息和代码将有助于更轻松地重现问题。
使用 RibbonControlsLibrary 中的 Microsoft.Windows.Controls.Ribbon.RibbonComboBox感觉就像走过一个充满 bug 的大沼泽,如果你知道解决办法的话就不会这么做。
任何人。我遇到的最大问题是数据绑定(bind)我的 SelectedItem。
以下是我开始的内容(在我发现 RibbonGallery 之后?)。将 ItemsSource 和 SelectedItem 放在 ComboBox 的子元素上,甚至不在同一级别上,已经让我感到紧张,但这似乎是正确的。
在示例应用程序中,我在 ViewModel 的构造函数中设置 SelectedItem。但是,运行应用程序时,不会显示 SelectedItem。甚至 VS 设计器也正确显示了“第二个选项”!
正在运行的应用程序: VS设计师:
调试 SelectedItem setter 时,您会注意到多次传递。第一次将其设置为 ctor 中的“第二个选项”后(1,请参阅下面的调试日志),它将重置为 null (2)(通过外部代码,我认为是在控件本身中)。当在 UI 中打开下拉列表时,它将再次设置为 null (3),然后在选择一个值时,两次设置为该值 (4,5)。我选择“第二个选项”,然后使用“第一个选项”重复该过程 (6-9)。这生成了以下日志(忽略功能区控件中的一千零一个绑定(bind)异常...):
最大的问题显然是(2),它正在重置我的初始选择。看起来当第一次显示控件时,它被重置。一个非常丑陋的解决方法是通过计时器设置该值。在这个示例应用程序中,在用户控件的 Loaded 事件中设置它确实对我有用,但在我的较重的现实应用程序中,它不起作用。无论如何,这一切都感觉不对劲。有谁知道更好的解决方案吗?
Xaml:
<UserControl x:Class="WpfApplication1.RibbonComboBoxDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:r="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.DataContext>
<local:ViewModel />
</UserControl.DataContext>
<Grid>
<r:Ribbon >
<r:RibbonTab Header="First Tab">
<r:RibbonGroup Header="Group">
<r:RibbonComboBox >
<r:RibbonGallery SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
<r:RibbonGalleryCategory ItemsSource="{Binding Controls}" DisplayMemberPath="Caption" />
</r:RibbonGallery>
</r:RibbonComboBox>
</r:RibbonGroup>
</r:RibbonTab>
<r:RibbonTab Header="Second Tab" />
</r:Ribbon>
</Grid>
</UserControl>
View 模型:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
namespace WpfApplication1
{
public class ViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public ObservableCollection<ControlBaseModel> Controls { get; private set; }
private ControlBaseModel _selectedItem;
public ControlBaseModel SelectedItem { get { return _selectedItem; } set { LogSelectedItemChange(value); _selectedItem = value; OnPropertyChanged("SelectedItem"); } }
public ViewModel()
{
this.Controls = new ObservableCollection<ControlBaseModel>();
this.Controls.Add(new ControlBaseModel() { Caption = "first option" });
this.Controls.Add(new ControlBaseModel() { Caption = "second option" });
this.SelectedItem = this.Controls[1]; // set to second option
}
int i = 0;
private void LogSelectedItemChange(ControlBaseModel value)
{
i++;
string setObject = "null";
if (value != null)
{
setObject = value.Caption;
}
Debug.WriteLine(string.Format("{0}: SelectedItem.set(): {1}", i, setObject));
}
}
public class ControlBaseModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
private string _name;
public string Name { get { return _name; } set { _name = value; OnPropertyChanged("Name"); } }
private string _caption;
public string Caption { get { return _caption; } set { _caption = value; OnPropertyChanged("Caption"); } }
}
}
最佳答案
虽然 View/UserControl 加载事件是在我的应用程序中 ComboBox SelectedItem 重置为 null 之前发生的,但 ComboBox 加载事件实际上被触发了两次,第二次足够“晚”了。所以我目前的解决方案是这样的:
<r:RibbonComboBox>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding LoadedCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<r:RibbonGallery SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
<r:RibbonGalleryCategory ItemsSource="{Binding Controls}" DisplayMemberPath="Caption"/>
</r:RibbonGallery>
</r:RibbonComboBox>
View 模型:
private ControlBaseModel _lastNonNullSelectedItem;
public ObservableCollection<ControlBaseModel> Controls { get; private set; }
private ControlBaseModel _selectedItem;
public ControlBaseModel SelectedItem
{
get { return _selectedItem; }
set
{
if (value != null) { _lastNonNullSelectedItem = value; }
_selectedItem = value;
OnPropertyChanged("SelectedItem");
}
}
public ICommand LoadedCommand { get; private set; }
public ViewModel()
{
this.Controls = new ObservableCollection<ControlBaseModel>();
this.LoadedCommand = new ActionCommand(OnLoaded); // ActionCommand: simple implementation of ICommand
this.Controls.Add(new ControlBaseModel() { Caption = "first option" });
this.Controls.Add(new ControlBaseModel() { Caption = "second option" });
this.SelectedItem = this.Controls[1]; // set to second option
}
private void OnLoaded()
{
this.SelectedItem = _lastNonNullSelectedItem;
}
关于wpf - 如何对 Ribbons ComboBox 的 SelectedItem 进行数据绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15555449/
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 9年前关闭。 Improve this q
Office 2007/2010 团队的功能区荣誉是用户(菜单)的字体大小。 Windows Ribbon Framework功能区(由 MS Paint 和我的应用程序使用)忽略用户(即我的)字体首
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
当我启动一个新的 Excel Web 插件时,默认情况下空白项目有一个声明功能区的 MyAppName.xml 文件。该声明在 native Home Excel 选项卡下设置自定义组和自定义控件。
我想编写一个脚本(C# 或 AutoIT 或 VBScript .. 任何可行的),它应该 获取已打开的outlook应用程序的引用 遍历功能区以查找特定按钮 执行那个按钮点击 我该怎么做? 最佳答案
我想实现下面的图像,我可以使用的旧方法之一是将上面带有文本的贴纸保存为PNG,然后我用CSS将图像放置在盒子的顶部。 我不是专业的前端开发人员,但我想我可以用CSS3实现它。我的问题是如何用CSS3实
我在 API 网关和 Eureka 服务器上使用功能区作为负载平衡器。当客户端请求到达我的 API 网关时,它是每次都查询服务注册表以获取服务的可用实例,还是 Ribbon 将可用实例存储到其缓存中?
我有一个带有功能区 UI 的应用程序。在此 UI 中,存在一个带有附加菜单的按钮。我想要做的是从按钮处理程序访问菜单以动态添加和删除菜单项。 void CMyScrollView::OnMenuBut
前言 ribbon是一个客户端负载均衡器,它提供了对http和tcp客户端的行为的大量控制。我们在上篇(猛戳:springcloud系列——feign 服务调用)已经实现了多个服务之间的feign
ribbon简介 Ribbon 是 Netflix 发布的开源项目,主要功能是提供客户端的 软件负载均衡算法 ,将 Netflix 的中间层服务连接在一起。Ribbon 客户端组件提供一系列完善的
我有 Fluent Ribbon 控件。功能区菜单项按键提示显示不正确, 之前, 之后, 我已经为功能区菜单固定了行高..如何解决这个问题,谢谢 这是我的代码:
我是 WPF 的新手,正在尝试使用功能区控件。 我在应用程序中有一个选项卡,并希望隐藏标题但仍显示选项卡本身。 我一直在尝试各种属性和样式,但我只能隐藏整个选项卡。 我试过:ribbontab 可见性
我正在尝试为动态菜单绑定(bind)功能区控件。 顶部的功能区选项卡是我的“真实”功能区选项卡。底部开始是手动构建的,我正在用它来验证
我一直在看网站http://wpf.codeplex.com/并发现功能区控件找到了我的需求。 我想知道它是否需要机器上的任何 Office 许可证等,或者只需要工具包 dll。 它是否需要 Win-
我正在尝试在 .Net 4.5 Framework 上开发一个带有 Ribbon Control 的 WPF 应用程序。据我所知,MSDN Ribbon Class现在包含在 Net 4.5 框架中,
开门见山。 CSS 功能区应该附加到右侧边栏 div,但由于我不知道的原因,它一直附加到左侧。我几乎尝试了所有方法,但无法弄清楚。对于对 CSS 有更高理解的人来说,这一定很容易..so.. 这是代码
我试图在右侧获得与右侧相同的 3d 阴影效果。 请看这个 fiddle : http://jsfiddle.net/tdf84nL7/ WOW [CSS] .ribbon { position:rel
我在 MFC 应用程序的功能区上有一个 CMFCRibbonUndoButton。单击其 ID 时,我有一个处理程序 (ON_COMMAND(ID_EDIT_UNDO, ...))。但是,当按钮也在快
我们希望使用 HTTPS 进行基于 Feign 和 Ribbon 的微服务通信。这些服务基于 Spring Boot,并且正确设置了 tomcat。这些实例使用 HTTPS URL 注册,并且在 Eu
大家好,我是三友~~ 前几天有个大兄弟问了我一个问题,注册中心要集成SpringCloud,想实现SpringCloud的负载均衡,需要实现哪些接口和规范。
我是一名优秀的程序员,十分优秀!