VSTO 功能区组合框文本更改事件回调
VSTO Ribbon Combo Box Text Changed Event Call back
正在创建 VS Outlook 插件。
如何获取组合框的Text changes事件。当用户在组合框中输入一些文本时,我想调用我的 API 来检索数据
<comboBox id="cmbUsers" label="Users" showImage="false"
getItemCount="OnGetItemCount"
getItemLabel="OnGetItemLabel"
onChange="OnChange"
getText="GetText"
getKeytip="GetKeytip"/>
我尝试使用 OnChange 回调,但它不起作用。但是在功能区设计器中我可以看到 TextChange 事件。
如何使用回调事件进行文本更改
[ComVisible(true)]
public class Ribbon : Office.IRibbonExtensibility
{
private Office.IRibbonUI ribbon;
public Ribbon()
{
}
#region IRibbonExtensibility Members
public string GetCustomUI(string ribbonID)
{
return GetResourceText("UserOutlookAddin.Ribbon.xml");
}
#endregion
#region Ribbon Callbacks
//Create callback methods here. For more information about adding callback methods, select the Ribbon XML item in Solution Explorer and then press F1
public void Ribbon_Load(Office.IRibbonUI ribbonUI)
{
this.ribbon = ribbonUI;
}
public void OnActionCallback(Office.IRibbonControl control)
{
if (control.Id == "checkBox1")
{
MessageBox.Show("You clicked " + control.Id);
}
else
{
MessageBox.Show("You clicked a different control.");
}
}
public void OnGetItemCount(Office.IRibbonControl control)
{
Debug.WriteLine("##### Am OnGetItemCount");
}
public void OnGetItemLabel(Office.IRibbonControl control)
{
Debug.WriteLine("##### Am OnGetItemLabel");
}
public void OnChange(Office.IRibbonControl control)
{
Debug.WriteLine("##### Am OnChange");
}
public void GetText(Office.IRibbonControl control)
{
Debug.WriteLine("##### Am GetText");
}
public void GetKeytip(Office.IRibbonControl control)
{
Debug.WriteLine("##### Am GetKeytip");
}
#endregion
#region Helpers
private static string GetResourceText(string resourceName)
{
Assembly asm = Assembly.GetExecutingAssembly();
string[] resourceNames = asm.GetManifestResourceNames();
for (int i = 0; i < resourceNames.Length; ++i)
{
if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)
{
using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i])))
{
if (resourceReader != null)
{
return resourceReader.ReadToEnd();
}
}
}
}
return null;
}
#endregion
}
将 onChange
回调的签名更改为
public void OnChange(Office.IRibbonControl control)
到
public void OnChange(Office.IRibbonControl control, string text)
现在应该调用它了。
此外,您应该将 getItemCount
、getItemLabel
、getText
和 getKeytip
的签名从
更改为
public void OnGetItemCount(Office.IRibbonControl control)
public void OnGetItemLabel(Office.IRibbonControl control)
public void GetText(Office.IRibbonControl control)
public void GetKeytip(Office.IRibbonControl control)
到
public int OnGetItemCount(Office.IRibbonControl control)
public string OnGetItemLabel(Office.IRibbonControl control, int index)
public string GetText(Office.IRibbonControl control)
public string GetKeytip(Office.IRibbonControl control)
正在创建 VS Outlook 插件。
如何获取组合框的Text changes事件。当用户在组合框中输入一些文本时,我想调用我的 API 来检索数据
<comboBox id="cmbUsers" label="Users" showImage="false"
getItemCount="OnGetItemCount"
getItemLabel="OnGetItemLabel"
onChange="OnChange"
getText="GetText"
getKeytip="GetKeytip"/>
我尝试使用 OnChange 回调,但它不起作用。但是在功能区设计器中我可以看到 TextChange 事件。
如何使用回调事件进行文本更改
[ComVisible(true)]
public class Ribbon : Office.IRibbonExtensibility
{
private Office.IRibbonUI ribbon;
public Ribbon()
{
}
#region IRibbonExtensibility Members
public string GetCustomUI(string ribbonID)
{
return GetResourceText("UserOutlookAddin.Ribbon.xml");
}
#endregion
#region Ribbon Callbacks
//Create callback methods here. For more information about adding callback methods, select the Ribbon XML item in Solution Explorer and then press F1
public void Ribbon_Load(Office.IRibbonUI ribbonUI)
{
this.ribbon = ribbonUI;
}
public void OnActionCallback(Office.IRibbonControl control)
{
if (control.Id == "checkBox1")
{
MessageBox.Show("You clicked " + control.Id);
}
else
{
MessageBox.Show("You clicked a different control.");
}
}
public void OnGetItemCount(Office.IRibbonControl control)
{
Debug.WriteLine("##### Am OnGetItemCount");
}
public void OnGetItemLabel(Office.IRibbonControl control)
{
Debug.WriteLine("##### Am OnGetItemLabel");
}
public void OnChange(Office.IRibbonControl control)
{
Debug.WriteLine("##### Am OnChange");
}
public void GetText(Office.IRibbonControl control)
{
Debug.WriteLine("##### Am GetText");
}
public void GetKeytip(Office.IRibbonControl control)
{
Debug.WriteLine("##### Am GetKeytip");
}
#endregion
#region Helpers
private static string GetResourceText(string resourceName)
{
Assembly asm = Assembly.GetExecutingAssembly();
string[] resourceNames = asm.GetManifestResourceNames();
for (int i = 0; i < resourceNames.Length; ++i)
{
if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)
{
using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i])))
{
if (resourceReader != null)
{
return resourceReader.ReadToEnd();
}
}
}
}
return null;
}
#endregion
}
将 onChange
回调的签名更改为
public void OnChange(Office.IRibbonControl control)
到
public void OnChange(Office.IRibbonControl control, string text)
现在应该调用它了。
此外,您应该将 getItemCount
、getItemLabel
、getText
和 getKeytip
的签名从
public void OnGetItemCount(Office.IRibbonControl control)
public void OnGetItemLabel(Office.IRibbonControl control)
public void GetText(Office.IRibbonControl control)
public void GetKeytip(Office.IRibbonControl control)
到
public int OnGetItemCount(Office.IRibbonControl control)
public string OnGetItemLabel(Office.IRibbonControl control, int index)
public string GetText(Office.IRibbonControl control)
public string GetKeytip(Office.IRibbonControl control)