English 中文(简体)
WPF-ContextMenu - how to Disable background change on mouse over or Focus
原标题:WPF-ContextMenu - how to Disable background change on mouse over or focus

its my first question in StackOverFlow ,

I have a text box , when clicking on,it shows a context menu , I have some control (user control or ..) in context menu.

everything is ok except in mouse over , all my controls get focus and their background change to blue , its so awful, another problem , in context menu , there is an vertical line , and an Icon place in left of it , How Can I remove it ?

C# Code :

private void textBox1_GotMouseCapture(object sender, MouseEventArgs e)
    {

        textBox1.ContextMenu.PlacementTarget = textBox1;
        textBox1.ContextMenu.IsOpen = true;
        textBox1.Focus();
}

和《刑法》:

<TextBox Height="23" HorizontalAlignment="Left" Margin="12,55,0,0"
Name="textBox1" VerticalAlignment="Top"
Width="120" MouseDown="textBox1_MouseDown" 
GotMouseCapture="textBox1_GotMouseCapture"
ContextMenuService.HasDropShadow="False" 
ContextMenuService.ShowOnDisabled="True" 
TextChanged="textBox1_TextChanged">
<TextBox.ContextMenu>
<ContextMenu Name="ctm" Placement="Relative" 
    Focusable="False" HasDropShadow="False" 
    VerticalOffset="23" HorizontalOffset="0">
    <StackPanel Margin="0" >
        <TextBox Text="testing..." Name="testing"></TextBox>
    </StackPanel>                    
</ContextMenu>
</TextBox.ContextMenu>
</TextBox>

感谢大家。

问题回答

one way to solve your "color" problem. you can override the systemcolors to get the behavior you want. just choose the SystemColor you need to override.

<ContextMenu>
   <ContextMenu.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightBlue"/>
   </ContextMenu.Resources>

EDIT:

i 在我的背景中,用以下文字确定甄选栏目透明,选定项目为绿地。

<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="DarkGreen"/>




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签