Here is my problem : I created a programm with Fluent ribbon, and when I want to disable a ribbon, I need to use the following code :
Code WPF :
<Fluent:RibbonGroupBox x:Name="GpRibbonFormats" ...>
<Fluent:Button x:Name="AjoutTole" Header="{x:Static p:Resources.Ajouter}">
<Fluent:Button.ToolTip>
<Fluent:ScreenTip x:Name="ScreenTipAjoutTole"...>
</Fluent:ScreenTip>
</Fluent:Button.ToolTip>
</Fluent:Button>
<Fluent:Button x:Name="EditQtyFormat" ...>
<Fluent:Button.ToolTip>
<Fluent:ScreenTip x:Name="ScreenTipEditQtyFormat"...>
</Fluent:ScreenTip>
</Fluent:Button.ToolTip>
</Fluent:Button>
<Fluent:Button x:Name="DeleteFormat" SizeDefinition="Large">
<Fluent:Button.ToolTip>
<Fluent:ScreenTip x:Name="ScreenTipDeleteFormat" ...>
</Fluent:ScreenTip>
</Fluent:Button.ToolTip>
</Fluent:Button>
</Fluent:RibbonGroupBox>
Code Behind :
AjoutTole.IsEnabled = false;
ScreenTipAjoutTole.DisableReason = isBlocked;
EditQtyFormat.IsEnabled = false;
ScreenTipEditQtyFormat.DisableReason = isBlocked;
DeleteFormat.IsEnabled = false;
ScreenTipDeleteFormat.DisableReason = isBlocked;
It works fine but I would like to make a function like that, so I am sure I always send correct information in DisableReason :
DisableButton(Fluent:Button NameOfButton,string ReasonOfDisable)
{
NameOfButton.IsEnabled = false;
NameOfButton.AllScreenTipChild.DisableReason=ReasonOfDisable
}
The same way I would like to disable all a group of buttons :
DisableGroup(Fluent:RibbonGroupBox myGroup,string ReasonOfDisable)
{
foreach(Fluent:Button button in myGroup)
{
button.isEnable=false;
button.AllScreenTipChild.DisableReason=ReasonOfDisable;
}
}
How such a thing is it possible?I want to be able to do it from codebehind.
Edit :
When trying to get the children of my button, I return one element of type System.Windows.Controls.Border, which name is "border", but I don't have such element in my XAML file. I also tried to get children of my RibbonGroupBox, but in that case I return one grid (grid2), and that grid is not even in the Ribbon...
Code used :
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(DeleteOL); i++)
{
var child = VisualTreeHelper.GetChild(DeleteOL, i);
string monType = child.GetType().ToString();
if(monType== "System.Windows.Controls.Border")
{
System.Windows.Controls.Border bb = (System.Windows.Controls.Border)child;
string name = bb.Name;
}
}
Edit 2 :
I confirm that getChild doesn't work on ribbon(why?), but I could find how to get list of buttons in a group :
foreach(var item in GpRibbonFormats.Items)
{
if(item.GetType().ToString()=="Fluent.Button")
{
Fluent.Button button = (Fluent.Button)item;
button.IsEnabled = false;
}
}
Now I am still looking on how to find a button's ScreenTip