簡體   English   中英

WPF ContextMenu復雜項在單擊時保持打開狀態嗎?

[英]WPF ContextMenu complex item stays open on click?

所以我有一個復雜的上下文菜單。 它不僅僅包含菜單項。 它還具有單選按鈕,底部的堆棧面板上有一個integerupdown框。

上下文菜單

<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的文本區域時,上下文菜單將關閉。 這使得按原樣使用該物品幾乎是不可能的。 有沒有更好的方法可以執行我要在上下文菜單中執行的操作? 有沒有一種方法可以使上下文菜單保持打開狀態,直到用戶在菜單外單擊為止?

只需將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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM