11

我已经绑定了我的窗口的Height和。Width现在,Visual Studio 中的窗口太小了,我不能再处理它了。将默认值设置为HeightandWidth将解决我的问题。有可能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吗?如何?

4

1 回答 1

20

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解决您的小窗口问题。

于 2010-02-10T17:27:32.657 回答