jeudi 28 mai 2015

Togglebutton controlling popup window control

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.




Aucun commentaire:

Enregistrer un commentaire