Autor Beitrag
Christoph1972
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 690
Erhaltene Danke: 16


VS2015 Pro / C# & VB.Net
BeitragVerfasst: Do 14.11.13 22:09 
Hi Leute,

ich brauche mal wieder eine Idee von euch :-)

Und zwar habe ich ein UserControl mit einer ListBox als ContextMenuItem eingebunden, das funktioniert so weit. Nun ist es jedoch so, dass das ContextMenu schließt sobald ein ListBoxItem angeklickt wurde. Ich möchte dass das Menu geöffnet bleibt, da noch weitere Optionen eingestellt werden sollen.

Die ListBoxItems setzen sich aus einem RadioButton un einem ContentPresenter zusammen. Wenn der RadioButton direkt angeklickt wird, bleibt das Menu offen, landet der Klick auf dem CPresenter schließt es. Hat jemand eine Idee wie ich das schließen verhindern kann?

Hier mal mein XAML von dem UserControl:

ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
<UserControl x:Class="SpectrumComparer.MyTreeViewObjects.ContextMenuListBox"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
         d:DesignHeight="296" d:DesignWidth="200" Background="#FFF0F0F0" >
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="25" />
            <RowDefinition Height="5" />
            <RowDefinition Height="268*" />
        </Grid.RowDefinitions>
        <TextBlock FontSize="16" Text="Filter Expressions"></TextBlock>
        <Separator Foreground="Black" Height="2" Margin="0" Grid.Row="1"></Separator>
        <ListBox Background="#FFF0F0F0" HorizontalAlignment="Left" Width="200" BorderBrush="Transparent" Name="RadioListBox" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding Path=RefValues, UpdateSourceTrigger=PropertyChanged}" SelectionMode="Single" Grid.Row="2" >
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemTemplate>
                <DataTemplate >
                    <StackPanel Orientation="Horizontal" MinWidth="150" MaxWidth="150" Margin="0,5, 0, 5">
                        <RadioButton   Name="radioButton" IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem} }, Path=IsSelected, Mode=TwoWay}" />
                        <ContentPresenter Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}" Margin="5,0,0,0" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</UserControl>

_________________
Gruß
Christoph
Christoph1972 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 690
Erhaltene Danke: 16


VS2015 Pro / C# & VB.Net
BeitragVerfasst: Fr 15.11.13 16:53 
So, ich habe eine Lösung gefunden.

Ich hatte erst mein UserControl direkt als "MenuItem" angehängt. Mein UserControl hat aber nicht die Property "StaysOpenOnClick", genau das war mein Problem. Nun habe ich ein MenuItem angefügt und mein Control als dessen Header festgelegt, das funktioniert :-)

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
<Window.ContextMenu>
    <ContextMenu>
        <MenuItem StaysOpenOnClick="True" >
            <MenuItem.Header>
                <my:MyUserControl HorizontalAlignment="Left" x:Name="myUserControl1" VerticalAlignment="Top" />
            </MenuItem.Header>
        </MenuItem>
    </ContextMenu>
</Window.ContextMenu>


Vielen Dank!

_________________
Gruß
Christoph