0

Trying to add two states to a button, first click opens a canvas, the second closes the canvas.

<ToggleButton x:Name="retailButton" Content="Button" Canvas.Left="203" Canvas.Top="107" Width="327" Height="83" RenderTransformOrigin="0.49,0.398" Visibility="Visible" Opacity="0" Click="retailButton_Click" IsEnabled="True" >

not sure about the code behind?

elszeus
  • 131
  • 1
  • 2
  • 13
  • 1
    Give the canvas a Style with a trigger that opens/closes it depending on the value of `retailButton.IsChecked`. [Similar stuff in this answer here](http://stackoverflow.com/questions/40360608/one-popup-for-all-button/40362822#40362822). – 15ee8f99-57ff-4f92-890c-b56153 Nov 01 '16 at 16:57

1 Answers1

1

You could use binding and a converter

<UserControl.Resources> 
    <BooleanToVisibilityConverter x:Key="BoolToVis" />
</UserControl.Resources>
...
        <Canvas Visibility="{Binding ElementName=ToggleCanvasVisibility, Path=IsChecked, Converter={StaticResource BoolToVis}}}"/>
        <ToggleButton x:Name="ToggleCanvasVisibility"/>

This is very close to this post: Binding a Button's visibility to a bool value in ViewModel

Community
  • 1
  • 1
MDSBP
  • 56
  • 1
  • 6