Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Windos
win32.3rdparty
win32.directx.audio
win32.directx.ddk
win32.directx.graphics
win32.directx.input
win32.directx.managed
win32.directx.misc
win32.directx.networking
win32.directx.sdk
win32.directx.video
win32.dirx.grap.shaders
win32.gdi
win32.international
win32.kernel
win32.messaging
win32.mmedia
win32.networks
win32.ole
win32.rtc
win32.tapi
win32.tapi.beta
win32.tools
win32.ui
win32.wince
win32.wmi
windows.mediacenter
winfx.aero
winfx.announcements
winfx.avalon
winfx.collaboration
winfx.fundamentals
winfx.general
winfx.indigo
winfx.sdk
winfx.winfs
  
 
date: Thu, 11 Oct 2007 02:16:00 -0700,    group: microsoft.public.windows.developer.winfx.avalon        back       


ListBox, Style & ContextMenu   
Hi,

I have a problem. I am new to WPF and I thought I could set a ContextMenu 
for my ListBox via a Style so I wrote sth like this:

<Window x:Class="TestTheTestStudio.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300" Loaded="Window_Loaded">
    <Window.Resources>
        <Style TargetType="{x:Type ListBox}">
            <Setter Property="ContextMenu">
                <Setter.Value>
                    <ContextMenu Name="test">
                          <MenuItem Header="Test"/>
                    </ContextMenu>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <StackPanel>
        <Button x:Name="buttonTest" Click="buttonTest_Click">Add</Button>
        <ListBox>
            <ListBox.Items>
                <ListBoxItem>Test</ListBoxItem>
            </ListBox.Items>
        </ListBox>
    </StackPanel>
</Window>

My code compiles. But after that I get a Exception from the XamlReader 
saying that 
a object of type "System.Object" must not have content of type 
"System.Windows.Controls.ContextMenu". I do not understand what I am doing 
wrong...maybe it is sth very simple.

Thanks, Pan
date: Thu, 11 Oct 2007 02:16:00 -0700   author:   Pan Kessel

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us