Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WCF and WF
  4. MenuItem Command [modified]

MenuItem Command [modified]

Scheduled Pinned Locked Moved WCF and WF
wpfwcf
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    teejayem
    wrote on last edited by
    #1

    I have a menuitem which is bound to a command in my vm

    <MenuItem Header="_Up" Command="{Binding Path=UpCommand}" />

    this works great (canexecute fires and execute fires) except if canexecute returns false then the menuitem is disabled. I'd like to change the menuitem so that the visibility will be hidden/collapsed if CanExecute is returned false. Is there a way to do that (by changing the style) w/o creating a "menuitemviewmodel" or some clunky thing like that.

    Don't be overcome by evil, but overcome evil with good

    modified on Tuesday, December 29, 2009 3:12 PM

    M 1 Reply Last reply
    0
    • T teejayem

      I have a menuitem which is bound to a command in my vm

      <MenuItem Header="_Up" Command="{Binding Path=UpCommand}" />

      this works great (canexecute fires and execute fires) except if canexecute returns false then the menuitem is disabled. I'd like to change the menuitem so that the visibility will be hidden/collapsed if CanExecute is returned false. Is there a way to do that (by changing the style) w/o creating a "menuitemviewmodel" or some clunky thing like that.

      Don't be overcome by evil, but overcome evil with good

      modified on Tuesday, December 29, 2009 3:12 PM

      M Offline
      M Offline
      mcaizmb5
      wrote on last edited by
      #2

      Bind the visibility of the menuitem to its own isenabled property using a BooleanToVisibility converter. That should do it ;)

      T 1 Reply Last reply
      0
      • M mcaizmb5

        Bind the visibility of the menuitem to its own isenabled property using a BooleanToVisibility converter. That should do it ;)

        T Offline
        T Offline
        teejayem
        wrote on last edited by
        #3

        Yeah that's sort of what i went with except i used the same idea in a trigger

                <Style x:Key="MenuItemStyle" TargetType="{x:Type MenuItem}">
                    <Style.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
                <ContextMenu x:Key="menu">
                    <MenuItem Header="\_Up" Command="{Binding Path=UpCommand}" Style="{StaticResource MenuItemStyle}" />
                </ContextMenu>
        

        It still doesn't sit right with me. I wish i could change it to where it doesn't trigger off of the IsEnabled property. It just seems bad to trigger one property off of another property. I mean, theoretically a developer can trigger Visibility off Enabled, then trigger AllowDrop off Visibility, then trigger Focusable off AllowDrop (you get the point). Not that anyone would ever want to do that, but it does promote that behavior.

        Don't be overcome by evil, but overcome evil with good

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups