2014-10-27 31 views
2

所以我有一個複雜的上下文菜單。它沒有菜單項。它還有單選按鈕,底部有一個疊置面板,上面有一個插入面板。WPF ContextMenu複雜項目保持打開點擊?

contextmenu

<Button.ContextMenu> 
    <ContextMenu> 
     <RadioButton Tag="30" Content="30 seconds" GroupName="adLength" Checked="adLength_Checked" IsChecked="True"/> 
     <RadioButton Tag="60" Content="1 minutes" GroupName="adLength" Checked="adLength_Checked"/> 
     <RadioButton Tag="90" Content="1 min 30 sec" GroupName="adLength" Checked="adLength_Checked"/> 
     <RadioButton Tag="120" Content="2 minutes" GroupName="adLength" Checked="adLength_Checked"/> 
     <RadioButton Tag="150" Content="2 min 30 sec" GroupName="adLength" Checked="adLength_Checked"/> 
     <RadioButton Tag="180" Content="3 minutes" GroupName="adLength" Checked="adLength_Checked"/> 
     <Separator/> 
     <MenuItem x:Name="advert_Auto" Header="Run Automatically" IsCheckable="true" StaysOpenOnClick="True"/> 
     <StackPanel Orientation="Horizontal"> 
      <TextBlock>every</TextBlock> 
      <xctk:IntegerUpDown x:Name="advert_Time" Value="30" Minimum="15" Width="50" Margin="5,0" /> 
      <TextBlock>min</TextBlock> 
     </StackPanel> 
    </ContextMenu> 
</Button.ContextMenu> 

<MenuItem>對象具有用於staysopenonclick的選項;當有人點擊該項目時,上下文菜單保持打開狀態。 <RadioButton>對象沒有這個選項,但它們保持打開狀態。

我遇到的問題是最後一個項目<StackPanel>。當用戶點擊IntegerUpDown的文本區域時,上下文菜單關閉。這使得使用該產品變得非常不可能。有沒有更好的方法來做我想要在上下文菜單中做的事情?有沒有辦法保持上下文菜單打開,直到用戶在菜單外單擊?

回答

2

只需將StackPanel填入MenuItem作爲其標題並將StaysOpenOnClick屬性設置爲true

<MenuItem StaysOpenOnClick="True"> 
    <MenuItem.Header> 
     <StackPanel Orientation="Horizontal"> 
      <TextBlock>every</TextBlock> 
      <TextBox Text="30" Width="50" Margin="5,0" /> 
      <TextBlock>min</TextBlock> 
     </StackPanel> 
    </MenuItem.Header> 
</MenuItem> 
+0

謝謝,工作。 – 2014-10-27 15:05:14