I have a PopUp control being controlled by a `ToggleButton`. This works fine, however i do not like the appearence of the `ToggleButton` so I have applied a control template to make the `ToggleButton` look like a `CheckBox`. I would like the `CheckBox` to be checked when the PopUp is visible, and become unchecked when the PopUp window disappears. My current code is as follows, but I am not getting the desired effect.

```
    <ToggleButton x:Name="LegendToggleButton" 
        HorizontalAlignment="Right" 
        IsChecked="{Binding IsOpen, ElementName=LegendPopup, mode=OneWayToSource}">
        <ToggleButton.Template>
            <ControlTemplate TargetType="ToggleButton">
                <CheckBox x:Name="LegendCheckBox" Content="Show Legend" Style="{StaticResource {x:Type CheckBox}}" 
                          IsChecked="{Binding IsOpen, ElementName=LegendPopup, Mode=TwoWay}" />
            </ControlTemplate>
        </ToggleButton.Template>
    </ToggleButton>

    <Popup x:Name="LegendPopup"
           PlacementTarget="{Binding ElementName=LegendToggleButton}"
           Placement="Top"
           PopupAnimation="Fade"
           StaysOpen="False">

```

This works fine in terms of making the window appear when the toggle button is clicked (with the `CheckBox` becoming checked, and then unchecking and hiding the popup when other controls are clicked. However, if i show the PopUp by clicking the toggle button, and then click the toggle button again (which i would expect to hide the popup), the popup momentarily closses and then straight away reappears.