开发者

WP7 -- Context Menu Forces Black Background for Listbox

开发者 https://www.devze.com 2023-03-22 22:44 出处:网络
This is probably an easy one... I have a Listbox with a ContextMenu embedded in it, and every time the ContextMenu appears, the Listbox changes its background to opaque black. How do I prevent this fr

This is probably an easy one... I have a Listbox with a ContextMenu embedded in it, and every time the ContextMenu appears, the Listbox changes its background to opaque black. How do I prevent this from happening?

Here is some sample XAML:

<ListBox x:Name="FolderItems" ItemTemplate="{StaticResource ItemTemplate}" ItemContainerStyle="{StaticResource ItemListBox}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" ItemsSource="{Binding FolderItems}">
    <toolkit:ContextMenuService.ContextMenu> 
       <toolkit:ContextMenu 
         x:Name="FolderContextMenu"
         Margin="20"
         Background="WhiteSmoke"
         BorderBrush="Black"
      开发者_开发百科   BorderThickness="1.0"
         Closed="ContextMenu_Closed">
              <toolkit:MenuItem Loaded="ContextMenuItem_Loaded" 
                  Opacity="0.0" Margin="5" Background="Transparent"
                  Click="ContextMenuItem_Click" Name="ContextMenuDelete">
                  <toolkit:MenuItem.Header>
                      <TextBlock Text="delete" FontFamily="Segoe WP Bold"/>
                  </toolkit:MenuItem.Header>
              </toolkit:MenuItem>
          </toolkit:ContextMenu>
  </toolkit:ContextMenuService.ContextMenu>
</ListBox>

Thanks

Update

I still haven't figured out why the entire listbox goes black when the context menu appears. I've set everything I can think of to a transparent brush.


I fixed this for my situation by opening up the toolkit (downloading the source: Silverlight Toolkit), and editing the color values myself in ContextMenu.cs . Then, I rebuilt and targeted the dll that I created rather than the one from the installer.

The only issue is that I will now need to do this application specific, but at least I can have a resolution. I believe also that if you set IsZoomEnabled=false, it won't have this behavior in the first place, but it's a different experience.

Here's my edited version: Pastebin

Check out the lines like this, they're the ones you'll need to change:

// Create a layer for the element's background
                UIElement elementBackground = new Rectangle
                {
                    Width = ownerElement.ActualWidth,
                    Height = ownerElement.ActualHeight,
                    Fill = new SolidColorBrush(Colors.White),
                };

Good luck!


There's a simple way to do this. For some reason MS Access complements the colors when using a list box. If you set the foreground to red, it will show green, etc.

So, set the background color to black (0) and the foreground color to white (16777215). Counter-intuitive but it works is MS Access 2002.


Without seeing the template you're using I can't say for sure but you've probably hardcoded a background value but not considered the different states of the list items and the default state colour/value is being displayed

0

精彩评论

暂无评论...
验证码 换一张
取 消