是否可以在WPF/.Net 4.0中使用xaml样式定位窗口



在.Net 3.5中,我们过去可以做一些类似的事情:

<Style.Triggers>
 <DataTrigger Binding="{Binding Path=SOMEPROPERTY}" Value="False">
  <Setter Property="Left" Value="100" />
  <Setter Property="Top" Value="50" />
 </DataTrigger>
</Style.Triggers>

并且它将窗口定位在给定的坐标处。

在.Net 4.0中,左侧和顶部不能再通过xaml样式进行调整。

除了将这一切转移到C#中之外,有人知道一个适用于.Net 4.0的解决方案吗?

既然你不应该像文档本身所说的那样使用样式,你就没有太多选择,所以你必须采取不同的做法。

你可以做的一件事是使用Blend SDK的交互性,例如:

xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
<!-- Place this anywhere inside the Window as it is attached -->
<i:Interaction.Triggers>
    <ei:DataTrigger Binding="{Binding TestString}" Value="42">
        <ei:ChangePropertyAction PropertyName="Top" Value="0" />
        <ei:ChangePropertyAction PropertyName="Left" Value="0" />
    </ei:DataTrigger>
</i:Interaction.Triggers>

最新更新