我绑定了我窗口的Height
和Width
。现在,Visual Studio中的窗口非常小,我无法继续使用它。将默认值设置为Height
和Width
可以解决我的问题。可以在Binding
吗?
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Class="Sth.MainWindow"
x:Name="Window"
Width="{Binding Path=WidthOfImage, Mode=TwoWay}"
Height="{Binding Path=HeightOfImage, Mode=TwoWay}"
>
...
</Window>
我们可以在WPF Binding
中设置默认值吗?怎么样?
答案 0 :(得分:13)
请参阅FallbackValue
:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Class="Sth.MainWindow"
x:Name="Window"
Width="{Binding Path=WidthOfImage, Mode=TwoWay, FallbackValue=200}"
Height="{Binding Path=HeightOfImage, Mode=TwoWay, FallbackValue=150}"
>
...
</Window>