0

I have a group of the button mui:LinkGroup which contains four buttons mui:Link which one I disactivate it and remain in gray.

Here is my code with Xaml and C#

 <mui:LinkGroup DisplayName="{x:Static p:Resources.Link_Transport}" x:Name="transport">
            <mui:LinkGroup.Links>
                <mui:Link DisplayName="{x:Static p:Resources.Link_Moyens_Transport}" Source="/Pages/Transports/ListTransport.xaml" />
                <mui:Link DisplayName="{x:Static p:Resources.Link_Voyages}" Source="/Pages/Voyages/ListVoyage.xaml" />
                <mui:Link DisplayName="{x:Static p:Resources.Link_Allottement}" Source="/Pages/Allottement/EffecterSiege.xaml" />
                <mui:Link DisplayName="{x:Static p:Resources.Link_Etat_Voyages}"  Source="/Pages/Transports/TransportTravels.xaml" />
            </mui:LinkGroup.Links>
        </mui:LinkGroup>

I do not like to completely remove the button or put it in comment and thank you in advance for help :)

waj
  • 11
  • 4
  • What do you mean with Diactivate ? You can disable it: Enable=False, Will be grayed out. or You can hide it. Visibility = Visibility.Collapsed. Will not be shown or take any space – Nawed Nabi Zada Mar 12 '19 at 10:28
  • Yes Enable=False but i don't found it in my property of mui:Link – waj Mar 12 '19 at 10:30
  • mui:Link is a custom control... you have to implement the functionality you need, or inherit it from a proper control – Nawed Nabi Zada Mar 12 '19 at 10:43

1 Answers1

0

A Link cannot be disabled directly. What you can do is to find the corresponding ListViewItem in the visual tree and disable this one. You have to do this programmatically:

public partial class MainWindow : ModernWindow
{
    public MainWindow()
    {
        InitializeComponent();
        this.Loaded += (s, e) => 
        {
            ModernMenu mm = FindVisualChildren<ModernMenu>(this).FirstOrDefault();
            if(mm != null)
            {
                ListBox lb = FindVisualChildren<ListBox>(mm)?.ElementAt(1);
                if (lb != null)
                {
                    ListBoxItem link = FindVisualChildren<ListBoxItem>(lb).FirstOrDefault(x => x.Content == theLink);
                    if (link != null)
                        link.IsEnabled = false;
                }
            }
        };
    }
}

Name the link that you want to display using an x:Name attribute in the XAML:

<mui:Link x:Name="theLink" DisplayName="..." ... />
mm8
  • 163,881
  • 10
  • 57
  • 88