Creating Office 2010
style Minimize Ribbon and Help button in WPF Infragistic Grid
Infragistic 12.2 WPF Grid designer not support to add
Minimize Ribbon and Help button.
Screen shot of Actual Implementation
Follow below steps to achieve this in MVVM application
1)
Create a UserControl ‘RibbonControlView’ and add
a xamRibbon on that.
2)
In the Ribbon designer IsMinimized property to
bind ViewModel object RibbonMinState
<my:XamRibbon Name="xamRibbon" IsMinimized="{Binding RibbonMinState, Mode=TwoWay}">
<my:XamRibbon.ApplicationMenu>
3)
Create a RibbonControlViewModel class for this RibbonControlView
4)
Add following properties in the viewmodel
private bool
ribbonMinState;
public bool RibbonMinState
{
get
{
return
ribbonMinState;
}
set
{
ribbonMinState = value;
MinmizeButtonIconchange(value);
NotifyPropertyChanged("RibbonMinState");
}
}
private
string minBtnToolTip;
public string MinBtnToolTip
{
get
{ return minBtnToolTip; }
set
{ minBtnToolTip = value; NotifyPropertyChanged("MinBtnToolTip"); }
}
private
BitmapImage _minBtnIcon;
public BitmapImage MinBtnIcon
{
get
{ return _minBtnIcon; }
set
{ _minBtnIcon = value; NotifyPropertyChanged("MinBtnIcon"); }
}
private
void MinmizeButtonIconchange(bool flg)
{
if
(flg)
{
MinBtnToolTip = "Expand
the Ribbon (Ctrl+F1)";
MinBtnIcon = new BitmapImage(new Uri(@"/Images/arrowdown.png", UriKind.Relative));
}
else
{
MinBtnToolTip = "Minimize the Ribbon (Ctrl+F1)";
MinBtnIcon = new BitmapImage(new Uri(@"/Images/arrowup.png", UriKind.Relative));
}
}
5)
Add following method to the RibbonControlView.xaml.cs
file
public void xamRibbonPostTabButton()
{
var
context = this.DataContext as RibbonControlViewModel;
XamRibbon
ribbon = this.xamRibbon;
XamTabControl
xtc = Utilities.GetDescendantFromType(ribbon,
typeof(XamTabControl),
true) as XamTabControl;
if
(null != xtc)
{
StackPanel
st = new StackPanel();
st.Orientation = Orientation.Horizontal;
ButtonTool
btnMin = new ButtonTool();
btnMin.Height = 22;
btnMin.Width = 22;
context.RibbonMinState = false;
Binding
BinidngIcon = new Binding("MinBtnIcon");
BinidngIcon.Source = context;
btnMin.SetBinding(ButtonTool.SmallImageProperty, BinidngIcon);
Binding
BindingIconTooltip = new Binding("MinBtnToolTip");
BindingIconTooltip.Source =
context;
btnMin.SetBinding(ButtonTool.ToolTipProperty, BindingIconTooltip);
btnMin.Click += new System.Windows.RoutedEventHandler(btnMin_Click);
ButtonTool
btnHelp = new ButtonTool();
btnHelp.Height = 22;
btnHelp.Width = 22;
btnHelp.ToolTip = "Help(F1)";
btnHelp.Command = ApplicationCommands.Help;
btnHelp.SmallImage = new BitmapImage(new Uri(@"/Images/help.png", UriKind.Relative));
st.Children.Add(btnMin);
st.Children.Add(btnHelp);
xtc.PostTabItemContent = st;
}
}
6)
Add the RibbonControlView user control in a Mainwindow as follows
<Views:RibbonControlView x:Name="ribbonCtrl"/>
7)
MainWindow loaded event call the method as follows
this.ribbonCtrl.xamRibbonPostTabButton();
Contact me
for full working solution and further query
Too much C# code. You should push more of this into XAML. And if you've got code behind (i.e. the window loaded event) then it's not MVVM.
ReplyDeleteIt's a shame, I was hoping to see how to do this but I'm not going to introduce a bunch of technical debt by writing a bunch of unnecassary code. I'll keep looking for the solution.