locked
Custom controls within context menus RRS feed

  • Question

  • Is it possible to add a custom control to a context menu in WPF? Or setup a context menu with 3 textboxes and some text within a context menu? The idea is that the user would be able to select multiple items then using a context menu set some properties that all 3 contain at the same time. If there might be a better way to obtain this same thing im open to other ideas. 
    Sunday, March 16, 2014 11:59 PM

Answers

  • Hi,

    of course is that possible:

    <ListView.ContextMenu>
        <ContextMenu>
            <MenuItem Header="Set values">
                <MenuItem>
                    <MenuItem.Header>
                        <StackPanel>
                            <TextBox x:Name="t1" Width="50" />
                            <TextBox x:Name="t2" Width="50" />
                            <Button Content="Set" Click="Button_Click" />
                        </StackPanel>
                    </MenuItem.Header>
                </MenuItem>
            </MenuItem>
        </ContextMenu>
    </ListView.ContextMenu>

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        string val1 = t1.Text;
        string val2 = t2.Text;
    }

    You could alternatively use a click event to open a dialog, where you could edit the properties.


    Chris

    Code Samples: Code Samples
    Chrigas Blog: Chrigas Blog

    Monday, March 17, 2014 1:19 AM

All replies

  • Hi,

    of course is that possible:

    <ListView.ContextMenu>
        <ContextMenu>
            <MenuItem Header="Set values">
                <MenuItem>
                    <MenuItem.Header>
                        <StackPanel>
                            <TextBox x:Name="t1" Width="50" />
                            <TextBox x:Name="t2" Width="50" />
                            <Button Content="Set" Click="Button_Click" />
                        </StackPanel>
                    </MenuItem.Header>
                </MenuItem>
            </MenuItem>
        </ContextMenu>
    </ListView.ContextMenu>

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        string val1 = t1.Text;
        string val2 = t2.Text;
    }

    You could alternatively use a click event to open a dialog, where you could edit the properties.


    Chris

    Code Samples: Code Samples
    Chrigas Blog: Chrigas Blog

    Monday, March 17, 2014 1:19 AM
  • Excelent. thank you. that helps me out a TON!

    Monday, March 17, 2014 1:32 AM