none
How to use a splitbutton with a disabled main command?

    General discussion

  • I am using the SplitButton of David Anson from here:

    http://blogs.msdn.com/b/delay/archive/2010/06/11/splitbuttoning-hairs-two-fixes-for-my-silverlight-splitbutton-menubutton-implementation-and-true-wpf-support.aspx

    I THOUGHT there was a split button somewhere in the Toolkit, but I didn't turn one up.  And the question is kind of general and not limited to the SplitButton, but helps to highlight the problem.

    Here is my xaml:

             <my:SplitButton 
                Name="splitButton1" 
                Command="{Binding SaveCommand}"
                Style="{StaticResource MainSaveTemplateStyle}"
                Visibility="{Binding Settings.HasAlternateSaveCommands, Converter={StaticResource BooleanToVisibility}}"
                Margin="10"
                >
                <my:SplitButton.ButtonMenuItemsSource>
                   
                   <toolkit:MenuItem HeaderTemplate="{StaticResource SaveTemplate}"         Command="{Binding SaveCommand}">
                      <toolkit:MenuItem.Icon>
                         <Image Source="/Images/disk.png" Stretch="Uniform" Margin="5,1" HorizontalAlignment="Center" VerticalAlignment="Center" />
                      </toolkit:MenuItem.Icon>
                   </toolkit:MenuItem>
                   
                   <toolkit:Separator/>
                   
                   <toolkit:MenuItem HeaderTemplate="{StaticResource SaveWithDataTemplate}" Command="{Binding SaveAsCopyWithDataCommand}" 
                      Visibility="{Binding Settings.ShowObservationSaveWithData,Converter={StaticResource BooleanToVisibility}}"
                      >
                      <toolkit:MenuItem.Icon>
                         <Image Source="/Images/disk.png" Stretch="Uniform" Margin="5,1" HorizontalAlignment="Center" VerticalAlignment="Center" />
                      </toolkit:MenuItem.Icon>
                   </toolkit:MenuItem>
                   
                   <toolkit:MenuItem HeaderTemplate="{StaticResource SaveWithoutDataTemplate}" Command="{Binding SaveAsCopyWithoutDataCommand}" 
                      Visibility="{Binding Settings.ShowObservationSaveWithoutData,Converter={StaticResource BooleanToVisibility}}"
                      >
                      <toolkit:MenuItem.Icon>
                         <Image Source="/Images/disk.png" Stretch="Uniform" Margin="5,1" HorizontalAlignment="Center" VerticalAlignment="Center" />
                      </toolkit:MenuItem.Icon>
                   </toolkit:MenuItem>
                   
                </my:SplitButton.ButtonMenuItemsSource>
             </my:SplitButton>
     

    And here are some of the templates and styles:

       <UserControl.Resources>
          <local:DataContextProxy x:Key="DataContextProxy1" />
          <system:String x:Key="SaveText">Save</system:String>
    
          <DataTemplate x:Key="MainSaveTemplate">
             <StackPanel Orientation="Horizontal" ToolTipService.Placement="Bottom">
                <ToolTipService.ToolTip >
                   <TextBlock>
                      <Run Text="Save the current"/>
                      <Run Text="{Binding Source={StaticResource DataContextProxy1}, Path=DataSource.ObservationLabel}"/>
                   </TextBlock>
                </ToolTipService.ToolTip>
                <Image Source="/Images/disk.png" Stretch="Uniform" Margin="5,1" HorizontalAlignment="Center" VerticalAlignment="Center" />
                <TextBlock Text="{StaticResource SaveText}" VerticalAlignment="Center" />
             </StackPanel>
          </DataTemplate>
    
          <DataTemplate x:Key="SaveTemplate">
             <StackPanel Orientation="Horizontal" ToolTipService.Placement="Bottom">
                <ToolTipService.ToolTip >
                   <TextBlock>
                      <Run Text="Save changes to the current"/>
                      <Run Text="{Binding Source={StaticResource DataContextProxy1}, Path=DataSource.ObservationLabel}"/>
                   </TextBlock>
                </ToolTipService.ToolTip>
                <TextBlock Text="{StaticResource SaveText}" VerticalAlignment="Center" />
             </StackPanel>
          </DataTemplate>

          <Style TargetType="Button" x:Key="MainSaveTemplateStyle">
             <Setter Property="HorizontalContentAlignment" Value="Stretch" />
             <Setter Property="ContentTemplate" Value="{StaticResource MainSaveTemplate}"/>
          </Style>

          <Style TargetType="Button" x:Key="SaveTemplateStyle">
             <Setter Property="HorizontalContentAlignment" Value="Stretch" />
             <Setter Property="ContentTemplate" Value="{StaticResource SaveTemplate}"/>
          </Style>

    So my "main" button says "Save" and has a command called SaveCommand.  The dropdown contains two other forms of "Save".  Now the problem is that initially I was only enabling the command when something was modified.  But if nothing is modified, I DO want to be able to get to the other forms of "Save".

    However, the disabled main command ALSO disables the dropdown.  So now I am forced to always enable the Save command just so I can get to the other forms of "Save".

    Can anyone think of a good work around to this so that the main Save command can be disabled, but the dropdown is still enabled?

    Friday, March 02, 2012 3:48 PM