Benutzer:MovGP0/WPF/Popup

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen
   MovGP0        Über mich        Hilfen        Artikel        Weblinks        Literatur        Zitate        Notizen        Programmierung        MSCert        Physik      


Popup class is similar to Window class, but without frame.

Open based on property state

[Bearbeiten | Quelltext bearbeiten]
<ToggleButton Name="button"> 
  <ToggleButton.Template>
    <ControlTemplate TargetType="ToggleButton">
      <TextBlock>Click Me</TextBlock>
    </ControlTemplate>
  </ToggleButton.Template>
</ToggleButton>
<Popup IsOpen="{Binding IsChecked, ElementName=button}" StaysOpen="False">
    <TextBlock>Popup Content</TextBlock>
</Popup>

Open based on Event

[Bearbeiten | Quelltext bearbeiten]
<Button x:Name="OpenPopup">Popup
    <Button.Triggers>
        <EventTrigger RoutedEvent="Button.Click"> <!-- TouchAndHoldGesture, PreviewTouchHoldGesture, etc. -->
            <EventTrigger.Actions>
                <BeginStoryboard>
                    <Storyboard>
                        <BooleanAnimationUsingKeyFrames 
                                 Storyboard.TargetName="ContextPopup" 
                                 Storyboard.TargetProperty="IsOpen">
                            <DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="True" />
                        </BooleanAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>
    </Button.Triggers>
</Button>
<Popup x:Name="ContextPopup"
       PlacementTarget="{Binding ElementName=OpenPopup}"
       StaysOpen="False">
    <TextBlock>Popup Content</TextBlock>
</Popup>