2009-07-29 7 views
1

WPFでは、クリックするとポップアップが既に開いているかどうかに応じてポップアップを開閉するボタンがあります(開いている場合は閉じる、閉じている場合は開く)。これを純粋にXAMLでやりたいこれは可能ですか?WPFポップアップボタン質問

おかげで、
ロイ

答えて

6

はい、あなたはToggleButtonではなく、標準のボタンを使用する必要があります。次に、Popup.IsOpenプロパティをToggleButton.IsCheckedプロパティにバインドすることができます。

これを示すXAMLスニペットが必要な場合は、数分で作成できます。しかし、これは十分に簡単であるはずです。

+0

この技術の例であります:http://stackoverflow.com/questions/361209/how-to-open-a-wpf-popup-when-another-control-is-clicked-using- xaml-markup-only/399824#399824 –

1

ここでは、動作として実装されている質問に対するnice solutionがあるため、ViewModelの背後にあるコード/ ViewModelとは関係ありません。

0

ちょうど@Charlieが言ったように、私はこの問題を解決します。 ここに私のコードはpage.xamlファイルです。ここで

<ToggleButton Name="MenuButton" Width="120" Height="40"/> 
      <Popup Width="130" Height="150" PlacementTarget="{Binding ElementName=MenuButton}" Placement="Bottom" AllowsTransparency="True" PopupAnimation="Fade" IsOpen="{Binding ElementName=MenuButton,Path=IsChecked}" StaysOpen="False"> 
       <Border Background="Black" CornerRadius="10"> 
        <Grid > 
         <Grid.RowDefinitions> 
          <RowDefinition /> 
          <RowDefinition /> 
          <RowDefinition /> 
         </Grid.RowDefinitions> 
         <Grid Grid.Row="0"> 
          <Button Content="Log" Width="120" Height="40"/> 
         </Grid> 
         <Grid Grid.Row="1"> 
          <Button Content="Shut Down" Width="120" Height="40"/> 
         </Grid> 
         <Grid Grid.Row="2"> 
          <Button Content="About..." Width="120" Height="40"/> 
         </Grid> 
        </Grid> 
       </Border> 
      </Popup>