using System.Windows;
using System.Windows.Forms;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
public class ButtonCmdHandler : System.Windows.Input.ICommand
{
public bool CanExecute( object parameter )
{
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute( object parameter )
{
}
}
class Commands
{
string gifFile = @"C:\Temp\GIF\cat.gif";
System.Drawing.Bitmap _bitmap;
BitmapSource _source;
static System.Windows.Forms.Control syncCtrl;
delegate void FinishedProcessingDelegate();
RibbonToolTip _toolTip_1;
private BitmapSource BitmapToBitmapSource( System.Drawing.Bitmap bitmap )
{
return Imaging.CreateBitmapSourceFromHBitmap( bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions() );
}
private void OnFrameChanged( object sender, EventArgs e )
{
if (syncCtrl.InvokeRequired)
syncCtrl.Invoke( new FinishedProcessingDelegate( FinishedProcessing ) );
else FinishedProcessing();
}
void FinishedProcessing()
{
System.Drawing.ImageAnimator.UpdateFrames();
_source = BitmapToBitmapSource( _bitmap );
_toolTip_1.ExpandedImage = _source;
}
[CommandMethod( "TEST" )]
public void CreateTab()
{
syncCtrl = new Control();
syncCtrl.CreateControl();
_bitmap = new System.Drawing.Bitmap( gifFile ); //tenor.gif
System.Drawing.ImageAnimator.Animate( _bitmap, OnFrameChanged );
RibbonControl ribbonControl = ComponentManager.Ribbon; // RibbonServices.RibbonPaletteSet.RibbonControl;
RibbonTab ribbonTab = new RibbonTab
{
Title = "Test",
Name = "Test_Tab",
Id = "TEST_ID"
};
ribbonControl.Tabs.Add( ribbonTab );
RibbonPanelSource panelSourceDocument = new RibbonPanelSource
{
Title = "Test",
Id = "ID_SrcPanel"
};
RibbonPanel panelDocument = new RibbonPanel
{
Source = panelSourceDocument
};
ribbonTab.Panels.Add( panelDocument );
_toolTip_1 = new RibbonToolTip
{
Title = "Этто кнопка 1",
Content = "Это моя подсказка",
ExpandedContent = "GIF-видео из внешнего файла",
ExpandedImage = _source //ExpandedVideo = new Uri( "X:/x.wmv" )
};
RibbonButton button = new RibbonButton
{
Text = "Кнопка 1",
Height = 16,
ToolTip = _toolTip_1,
CommandHandler = new ButtonCmdHandler()
};
RibbonRowPanel ribbonRow = new RibbonRowPanel();
ribbonRow.Items.Add( button );
panelSourceDocument.Items.Add( ribbonRow );
ribbonTab.IsActive = true;
button.IsActive = true;
}
}