Page 1 of 1

Context Menu Visual is null

Posted: 08 Feb 2022, 22:53
by ExtZGholson
Hello,

I am currently looking to add a context menu to assist in debugging. When I follow the context menu example provided the MenuItems do not seem to format correctly and a Noesis Error is throw; `Visual is null`. Am I missing something?
contextmenu.png
contextmenu.png (7.73 KiB) Viewed 1209 times
contextmenuerror.png
contextmenuerror.png (6.34 KiB) Viewed 1209 times
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
    <Border Width="360" Background="Gray" Padding="20">
      <Border.ContextMenu>
        <ContextMenu>
          <MenuItem Header="View">
            <MenuItem Header="Large icons"/>
            <MenuItem Header="Small icons"/>
            <MenuItem Header="List"/>
            <MenuItem Header="Details"/>
          </MenuItem>
          <MenuItem Header="Sort by">
            <MenuItem Header="Name"/>
            <MenuItem Header="Date"/>
            <MenuItem Header="Type"/>
          </MenuItem>
          <MenuItem Header="Refresh"/>
          <Separator/>
          <MenuItem Header="Pin to TaskBar" IsCheckable="True"/>
        </ContextMenu>
      </Border.ContextMenu>
      <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" IsHitTestVisible="False" Text="Right click to open Context Menu"/>
    </Border>
  </Grid>
</Grid>

Re: Context Menu Visual is null

Posted: 08 Feb 2022, 23:34
by ExtZGholson
I did some digging and found my answer! We need to make a visual template for the context menu.

Re: Context Menu Visual is null

Posted: 09 Feb 2022, 12:04
by sfernandez
Every control needs a template to render, so every time you see some control showing with a magenta background it would indicate it is using our internal debug templates.

We recommend to start by including our Theme in your application resources as base, then create the styles/template for the controls you are going to use.