views:

30

answers:

0

Hi I have a problem with context menu. I override default context menu from textbox with my own menu. The menu is created dynamicly and looks like that

ContextMenu menu = new ContextMenu()

      MenuItem  item1= new MenuItem();
                item1.Header = "First item";

      MenuItem item2 = new MenuItem();
               item2.Header = "Item 2"

This menu is assigned to textbox which is has this style

   <Style x:Key="DefaultStyle" TargetType="{x:Type TextBox}">
    <Setter Property="FontFamily" Value="Tahoma"/>
    <Setter Property="FontSize" Value="10"/>
    <Setter Property="HorizontalContentAlignment" Value="Center"/>
    <Setter Property="TextAlignment" Value="Center"/>
    <Setter Property="TextWrapping" Value="Wrap"/>
    <Setter Property="BorderBrush" Value="#A9C2DE"/>
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="Background" Value="Transparent"/>
     </Style>

My problem is that it seems that contextmenu gest style from textbox (at least part of it). What I mean is that all items headers in my contextmenu are centered. However is I remove this entry from my textbox style

<Setter Property="TextAlignment" Value="Center"/>

Everything is normal againt. However I want to have text in my textbox centered. Could somebody tell me why contextmenu seems to apply some part of parent style?