作为一个背景--Windows有一个Touch/TabletPCs工具,它可以根据你的"用手"移动弹出菜单/菜单的位置(以防止菜单出现在你的手下).
基本上这是做什么的,如果你被设置为"右手"(它似乎默认为你连接了一个触摸设备),你打开的每个弹出窗口被人为地踢到左边 - 这会导致我们尝试的大量布局问题并将弹出窗口与"弹出"项目对齐:
平板电脑设置设置为左手 - 不从Windows进行人工修正

平板电脑设置设置为右手 - Windows人工调整我们的定位

我们可以使用SystemParameters.MenuDropAlignment来检测此设置的设置,对于普通的弹出窗口,我们可以使用弹出窗口的实际宽度来调整它 - 但是对于动态弹出窗口以及当我们将右向左支撑放入混合时,这只是没有'工作.
目前看起来我们更有可能必须经历每个弹出窗口,手动设计一个值来调整踢,并为每个弹出一个类似的东西:
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Source={x:Static SystemParameters.MenuDropAlignment}}" Value="True"/>
<Condition Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=FlowDirection}" Value="RightToLeft"/>
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="HorizontalOffset" Value="-50"/> <!-- Set to arbitrary value to test -->
</MultiDataTrigger.Setters>
</MultiDataTrigger>
Run Code Online (Sandbox Code Playgroud)
那么..回到问题:-)有没有人知道如何停止WPF弹出窗口看这个设置呢?
对于那些没有触摸设备的用户,您可以通过运行以下方式访问Tablet PC设置:
C:\ Windows\explorer.exe shell ::: {80F3F1D5-FECA-45F3-BC32-752C152E456E}
并看到它为自己造成的混乱:-)
在将WPF应用程序移植到在VMware下运行的Windows 8实例(x64)时,我发现所有弹出窗口都与它们应该是的错误对齐.进一步调查显示,即使对于新创建的项目,这也是一个常见的"问题".WPF的弹出控件似乎改变了左右的含义!可以通过使用vs 2012创建一个wpf应用程序并在其中放置一些弹出窗口来显示问题,例如:
<Grid Background="Gray">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="129*"/>
<ColumnDefinition Width="264*"/>
<ColumnDefinition Width="124*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<DockPanel Grid.Row="1" Grid.Column="1" Background="LightGray">
<Popup StaysOpen="True" IsOpen="True" Grid.RowSpan="2" Placement="Right" AllowsTransparency="True" >
<TextBlock Text="Right" Foreground="White" />
</Popup>
<Popup StaysOpen="True" IsOpen="True" Grid.RowSpan="2" Placement="Left" AllowsTransparency="True" >
<TextBlock Text="Left" Foreground="White" />
</Popup>
<Popup StaysOpen="True" IsOpen="True" Grid.RowSpan="2" Placement="Top" AllowsTransparency="True" >
<TextBlock Text="Top" Foreground="White" />
</Popup>
<Popup StaysOpen="True" IsOpen="True" Grid.RowSpan="2" Placement="Bottom" AllowsTransparency="True" >
<TextBlock Text="Bottom" Foreground="White" />
</Popup>
</DockPanel>
</Grid>
Run Code Online (Sandbox Code Playgroud)
应该在左侧显示的弹出窗口实际显示在右侧,反之亦然,应该在左下方的弹出窗口显示在右下方等.
我的问题是:1)这是一个错误或功能吗?2)如果它是一个功能,如何对代码进行最小化更改,以便它们在Windows 7和Windows 8中以相同的方式执行?
我来自WinForms并且第一次自学WPF.
我以为我会首先在WPF中重新创建我的一个WinForms应用程序的界面,但我已经遇到了菜单问题.
我无法弄清楚为什么WPF应用程序中的菜单从右到左打开,当WinForms应用程序上的菜单从左到右打开时(这就是我想要的):
这是一个几乎没有默认设置的空白项目.这是XAML:
<Window x:Class="WpfTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Test" Height="541.771" Width="828.947" WindowStartupLocation="CenterScreen">
<DockPanel LastChildFill="False" Margin="0" Background="#FFFDFD9C">
<Menu x:Name="menu" Height="22" VerticalAlignment="Top" RenderTransformOrigin="1.79,0.076" DockPanel.Dock="Top" Margin="0">
<MenuItem Header="File">
<MenuItem Header="New Document"/>
<MenuItem Header="Open Template"/>
<MenuItem Header="Open Collateral"/>
<Separator/>
<MenuItem Header="Synchronise"/>
<Separator/>
<MenuItem Header="Build Document"/>
<MenuItem Header="Document History">
<MenuItem Header="Load Last Document"/>
</MenuItem>
<Separator/>
<MenuItem Header="Settings"/>
<Separator/>
<MenuItem Header="Exit"/>
</MenuItem>
<MenuItem Header="Help">
<MenuItem Header="User Guide"/>
<MenuItem Header="About"/>
</MenuItem>
</Menu>
<Rectangle Fill="#FFB8B8FF" Height="80" VerticalAlignment="Top" DockPanel.Dock="Top" Margin="0"/>
</DockPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
我遇到了一个奇怪的 WPF 弹出窗口放置问题。
我已经定义了这个 XAML:
<Window x:Class="PositionBug.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="300" Width="525">
<Grid>
<TextBlock Name="Textblock1" Height="60" Width="300" Background="LightGray" HorizontalAlignment="Center"
VerticalAlignment="Bottom">The PlacementTarget</TextBlock>
<Popup Name="Popup1" PlacementTarget="{Binding ElementName=Textblock1}" Placement="Top" Width="120" Margin="198,0,199,0" IsOpen="True">
<TextBlock Background="LightBlue" FontSize="18">This is a Popup</TextBlock>
</Popup>
</Grid>
Run Code Online (Sandbox Code Playgroud)
在大多数计算机上,这就是预期的结果:

然而,在一种特定计算机型号的多个单元上,结果如下所示:

有没有办法强制放置到顶部和左侧?