WSTM
Topic Author
Posts: 2
Joined: 10 Jan 2025, 01:12

Help with OpacityMask in Noesis

15 Apr 2025, 21:15

Hello, I'm hitting a dead end on trying to create a opacity mask on a listboxitem when a context menu is open.

The setup here is trying to create a dark background overlay when the context menu is open. I got the Dark overlay to appear correctly. But I'm having trouble to create a opacity mask to at as "Cut out" to display the listboxitem that triggers the context menu to open. I tried different methods to apply an opacity mask manually but they all fail to create a 'cut out'. Am I missing anything here? Would love to get some insights into this. Thanks in advance
 
<!--ControlTemplate-->
<!-- Original content -->
    <Grid x:Name="ContentGrid">
    <ContentPresenter/>
            <!-- Overlay system -->
            <Grid x:Name="DarkOverlay" Panel.ZIndex="100" Visibility="{Binding IsContextMenuOpen, Converter={StaticResource BoolToVisConverter}}">
                <Rectangle Fill="Black" Opacity="0.7"/>
                <Grid x:Name="OpacityMask">
                    <Grid.OpacityMask>
                        <VisualBrush>
                            <VisualBrush.Visual>
                                <Grid Background="Black">
                                    <Rectangle x:Name="ActiveSlotCutout" 
                                               Fill="White" 
                                               Width="56" Height="56"
                                               HorizontalAlignment="Left" 
                                               VerticalAlignment="Top"
                                               Margin="02"/>
                                </Grid>
                            </VisualBrush.Visual>
                        </VisualBrush>
                    </Grid.OpacityMask>
                    <Rectangle Fill="Black" Opacity="0.7"/>
                </Grid>
        </Grid>
    </Grid>
</Border>
 
User avatar
sfernandez
Site Admin
Posts: 3238
Joined: 22 Dec 2011, 19:20

Re: Help with OpacityMask in Noesis

16 Apr 2025, 11:34

I don't think that kind of OpacityMask can be created just using xaml because if it depends on the item that opens the ContextMenu.

But, couldn't you just darken the background of all the items except for the one that opens the context menu with some trigger? Like "if I'm not showing the context menu, then make semi-transparent black rectangle visible".
 
WSTM
Topic Author
Posts: 2
Joined: 10 Jan 2025, 01:12

Re: Help with OpacityMask in Noesis

16 Apr 2025, 16:24

Thanks for the reply.
I don't think that kind of OpacityMask can be created just using xaml because if it depends on the item that opens the ContextMenu.
I thought that might be the case, it cant be done via xaml alone
But, couldn't you just darken the background of all the items except for the one that opens the context menu with some trigger? Like "if I'm not showing the context menu, then make semi-transparent black rectangle visible".
I have a layer that darkens the background of all the items, but it covers the entire panel. I still need to make the listboxitem that triggered the context menu to appear, hence why I wanted to create a cutout to display the listboxitem from the darkened background. But this listboxitem is used in a listbox and the listbox is inside of a bigger usercontrol. So there are a few layers of content to pass through. So I'm curious if there is a better solution than creating a opacity mask to act as a cutout

Thanks for the help!
 
User avatar
sfernandez
Site Admin
Posts: 3238
Joined: 22 Dec 2011, 19:20

Re: Help with OpacityMask in Noesis

Yesterday, 13:55

The idea I proposed was to darken the ListBoxItem itself, not the whole ListBox. That way you decide, in a per-item basis, if you want to darken the item or not. I think it is a simpler approach to what you're trying to do. Could that work for you?

Who is online

Users browsing this forum: Semrush [Bot] and 32 guests