WPF绑定中的默认值

时间:2010-02-10 17:25:03

标签: .net wpf data-binding default-value

我绑定了我窗口的HeightWidth。现在,Visual Studio中的窗口非常小,我无法继续使用它。将默认值设置为HeightWidth可以解决我的问题。可以在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中设置默认值吗?怎么样?

1 个答案:

答案 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>

您也可以使用MinWidthMinHeight解决小窗口问题。