在WPF窗口中绑定高度属性,在有Width属性时不触发

时间:2012-11-16 12:13:11

标签: wpf xaml

我有以下XAML:

<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:WpfToolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
Title="{x:Static prop:Resources.Window1}" 
Height="{Binding WindowHeight}"
MinHeight="{Binding WindowMinHeight}"
MinWidth="500">

WindowHeight的吸气者按预期射击。

但是当我添加:

Width="750"

到XAML ..:

<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:WpfToolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
Title="{x:Static prop:Resources.Window1}" 
Height="{Binding WindowHeight}"
MinHeight="{Binding WindowMinHeight}"
Width="750"
MinWidth="500">

.. WindowHeight的吸气剂不起火。

为什么会这样?

谢谢,乔

1 个答案:

答案 0 :(得分:4)

试试这个:

<Window x:Name="window" x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WpfToolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
Title="{x:Static prop:Resources.Window1}"
Height="300"
Width="{Binding Height, ElementName=window}">