C# WPF Modern UI disable or hide LinkGroup

3.7k views Asked by At

Hi Im writing a WPF application that has user login. I use Modern UI for this application. The application has following LinkGroups:

<mui:ModernWindow.MenuLinkGroups>
    <mui:LinkGroup DisplayName="Group 1">
        <mui:LinkGroup.Links>
            <mui:Link DisplayName="A" Source="/Pages/A.xaml" />
            <mui:Link DisplayName="B" Source="/Pages/B.xaml" />
            <mui:Link DisplayName="C" Source="/Pages/C.xaml" />
        </mui:LinkGroup.Links>
    </mui:LinkGroup>
    <mui:LinkGroup DisplayName="Group 2">
        <mui:LinkGroup.Links>
            <mui:Link DisplayName="D" Source="/Pages/D.xaml" />
            <mui:Link DisplayName="F" Source="/Pages/F.xaml" />
            <mui:Link DisplayName="G" Source="/Pages/G.xaml" />
        </mui:LinkGroup.Links>
    </mui:LinkGroup>
</mui:ModernWindow.MenuLinkGroups>

I want to hide or disable Link group named "Group 2" depending on user ID. Is there a way to do it?

2

There are 2 answers

1
gaborhodi On BEST ANSWER

Maybe it is too late, but I think that had a solution. Since LinkGroup is not derived from UIElement it is not possible to hide it, but you can work around this. I'm sure that it isn't the clearest solution, but it worked for me.

You can reach your LinkGroups via

var window = App.Current.MainWindow as ModernWindow;
var toRemove = window.MenuLinkGroups.ElementAt(1);

MenuLinkGroups is a Collection<T> thus you can Add and Remove items.

window.MenuLinkGroups.Remove(toRemove);
0
Huseyin Yagli On

You can also generate a LinkGroupCollection after login and bind ModernWindow.MenuLinkGroups to this collection.