I have a relatively simple case where I want to repurpose a "Start" button with an "Abort" button after it is first clicked.
I'm wondering what is the best way to implement this button repurposing using XAML, hopefully declaratively rather than with a code-behind hack:
<DockPanel>
<Button x:Name="btnStart">Start</Button>
</DockPanel>
I tried the following with using two distinct Button
s and toggling the Visibility
property of each but it does not reflow the layout within the DockPanel
. I want the buttons to share the same layout space but mutually exclusively. This also has the problem where only the last element fills the dock panel and the first element is squished off to the left.
<DockPanel>
<Button x:Name="btnStart">Start</Button>
<Button x:Name="btnAbort" Visibility="Hidden">Abort</Button>
</DockPanel>
I prefer the two Button
approach so that I can have separate Click
event handlers. Please don't suggest naive solutions like dynamically adding/removing Button elements. I'd prefer a declarative approach if at all possible. Thanks!