How to open a Date input Popup on a BarButton Click: WPF

Viewed 29

I have this code and I would like to open a popup on a button click for users to input a date along with a date picker and then pass the date as the parameter.

<StackPanel>
      <BarContainerControl>
            <BarSubItem Content="List">
                  <BarButtonItem Content="Button" Command="{Binding cnt}"></BarButtonItem>
            </BarSubItem>
      </BarContainerControl>
</StackPanel>
private void HandleStuff()
{
 //Does stuff here
}

I have tried multiple things like PopupBaseEdit and FlyoutControl it didn't work.

1 Answers

There is a bit to do here. It is not too hard if you are just using the code-behind file, and a bit more involved if you are using MVVM.

You will need to declare the Command, implement an Action method for it (along with a second bool-valued function to determine whether it is enabled), instantiate the command linking it to the action and function, and then you can bind to it in your XAML (assuming that the Command is visible in the code-behind /the ViewModel has been set as the DataContext for your Window).

Do you have more of this done than just the little snippets you provided above? If not, there is a lot to do!

The alternative, if you don't care about MVVM and you are just using code-behind, is to attach an event handler in your code-behind to some event (like the Click event?) of your BarButtonItem and launch the DatePicker from there. That's much more in the style of Windows Forms than WPF, which intentionally builds heavily on the MVVM framework.

Related