开发者

Is it possible to position a window using a xaml style with WPF/.Net 4.0

In .Net 3.5 we used to be able to do something like:

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

and it would position the window at the coordinates given.

In .Net 4.0 Left and Top can not be adjusted via a xaml style anymore.

Other than moving this all into the C#, does an开发者_C百科yone know of a solution that works for .Net 4.0?


Well since you are not supposed to use a style as the documentation itself states you don't have much of a choice, you have to do it differently.

One thing you can do is to use Interactivity from the Blend SDK, e.g.:

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜