【问题标题】:How to keep Popup in Application window wpf如何在应用程序窗口中保留弹出窗口wpf
【发布时间】:2015-08-19 06:50:52
【问题描述】:

我一直试图在按下按钮时弹出一个窗口。 然而。假设我在该弹出窗口上有很多文本,然后它可以越过应用程序窗口边界。

如何让弹出窗口保持在 xaml 代码中的应用程序窗口范围内?

如果在 xaml 代码中提供一些关于如何告诉 Popup 元素保留在应用程序中的示例,那就太好了

谢谢

Xaml 代码:

...
    <ToggleButton Grid.Row="1" Grid.Column="1" Margin="0,4"
        x:Name="Somethingname"
        Height="30"
        Template="{StaticResource ComboBoxToggleButton}"
        Content="Hello man"/>
    <Popup Grid.Row="1" Grid.Column="1" x:Name="PopupMe"
            Style="{StaticResource PopupStyle}"
            ClipToBounds="True">

            <TreeView ItemsSource="{Binding SomeObservableCollection}"
                      Width="{Binding ElementName=DetaljerHjemmmelToggler, Path=ActualWidth}"
                      ItemTemplate="{StaticResource SomeTemplate}"
                      cal:Message.Attach="[Event SelectedItemChanged] = [Action TreeView_SelectedItem($this, $source)]">

             </TreeView>
    </Popup>
    ...     

在 ResourceDictionary XAML 文件中:

<HierarchicalDataTemplate x:Key="SomeTemplate" ItemsSource="{Binding ChildrenCollection}">
    <TextBlock Text="{Binding Path=TekstBlaaah}" Style="{StaticResource Label}"/>
</HierarchicalDataTemplate>

    <Style TargetType="{x:Type Popup}" x:Key="PopupStyle">
    <Setter Property="IsOpen" Value="{Binding ElementName=Somethingname, Path=IsChecked}"/>
    <Setter Property="AllowsTransparency" Value="True"/>
    <Setter Property="PlacementTarget" Value="{Binding ElementName=Somethingname}"/>
    <Setter Property="PopupAnimation" Value="Slide"/>
    <Setter Property="StaysOpen" Value="False" />
    <Setter Property="Placement" Value="Bottom"/>
</Style>

【问题讨论】:

标签: c# .net wpf user-interface caliburn


【解决方案1】:

检查一下:

Custom popup and windows in WPF the MVVM way

也可以提供样品

【讨论】:

  • 谢谢。似乎使用 ModalDialog 的一部分是有效的。只是不是全部,因为我以前使用过它,而且它非常有问题:((谢谢兄弟!:D)
猜你喜欢
  • 2016-05-10
  • 1970-01-01
  • 1970-01-01
  • 2012-07-15
  • 1970-01-01
  • 1970-01-01
  • 2013-07-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多