MaterialDesignInXAML / MaterialDesignInXamlToolkit

Google's Material Design in XAML & WPF, for C# & VB.Net.
http://materialdesigninxaml.net
MIT License
15.17k stars 3.43k forks source link

Make TimePicker Icon-Button hidable #3663

Closed SiggiSch closed 2 months ago

SiggiSch commented 2 months ago

It would be nice to hide the Clock-Button of the TimePicker control whenever I want to. For example I would like to hide the button, when the TimePicker is disabled. I could define a binding for that or just hide the button indefinitely.

Maybe with a dependency Property "bool HidePopupButton" or "Visibility HidePopupButton". So that I could use it like this:

<TimePicker HidePopupButton="True" />
or
<TimePicker HidePopupButton="{Binding IsEnabled, RelativeSource={RelativeSource Self}, Converter={StaticResource InvertBooleanConverter}}" />

We have similar controls in our project, where the button is hidden, when the control is disabled. With the TimePicker we want to have the same behaviour.

nicolaihenriksen commented 2 months ago

@SiggiSch Assuming you don't have any other Buttons added to the content of the TimePicker (where this behavior is not desirable), you should be able to add the resource below which simply amends the button style with a trigger that hides a button when TimePicker.IsEnabled=False.

<materialDesign:TimePicker materialDesign:HintAssist.HelperText="Helper text"
                           materialDesign:HintAssist.Hint="Pick Time"
                           Is24Hours="True"
                           IsEnabled="False"
                           Style="{StaticResource MaterialDesignOutlinedTimePicker}">
  <materialDesign:TimePicker.Resources>
    <Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
      <Style.Triggers>
        <Trigger Property="IsEnabled" Value="False">
          <Setter Property="Visibility" Value="Hidden" />
        </Trigger>
      </Style.Triggers>
    </Style>
  </materialDesign:TimePicker.Resources>
</materialDesign:TimePicker>

image

SiggiSch commented 2 months ago

Thanks @nicolaihenriksen and @Keboo !