WPF绑定中的默认值

11

我已经绑定了窗口的 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个回答

23

请查看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来解决小窗口的问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接