这可能是一个简单的...我有一个列表框,其中嵌入了一个上下文菜单,每次出现上下文菜单时,列表框都会将其背景更改为不透明的黑色。如何防止这种情况发生?
下面是一些示例 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>
谢谢
更新
我仍然不明白为什么当上下文菜单出现时整个列表框变黑。我把我能想到的所有东西都设置为透明画笔。
最佳答案
我通过打开工具包(下载源: Silverlight Toolkit )并自己在 ContextMenu.cs 中编辑颜色值来解决这个问题。然后,我重新构建并定位了我创建的 dll,而不是安装程序中的 dll。
唯一的问题是我现在需要针对这个应用程序进行具体操作,但至少我可以有一个解决方案。我还相信,如果您设置IsZoomEnabled=false,它一开始就不会出现这种行为,但这是一种不同的体验。
这是我编辑的版本:Pastebin
检查像这样的行,它们是您需要更改的行:
// Create a layer for the element's background
UIElement elementBackground = new Rectangle
{
Width = ownerElement.ActualWidth,
Height = ownerElement.ActualHeight,
Fill = new SolidColorBrush(Colors.White),
};
祝你好运!
关于silverlight - WP7——上下文菜单强制列表框为黑色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6838371/