Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# WPF Modern UI disable or hide LinkGroup

Tags:

c#

wpf

modern-ui

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?

like image 450
Burak Koray Balcı Avatar asked Jun 18 '15 09:06

Burak Koray Balcı


2 Answers

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);
like image 153
gaborhodi Avatar answered Nov 14 '22 21:11

gaborhodi


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

like image 24
Hüseyin Yağlı Avatar answered Nov 14 '22 23:11

Hüseyin Yağlı