【问题标题】:Default value in WPF BindingWPF 绑定中的默认值
【发布时间】:2011-01-15 09:13:43
【问题描述】:

我已经绑定了窗口的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 中设置默认值吗?怎么样?

【问题讨论】:

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


    【解决方案1】:

    见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>
    

    您还可以使用MinWidth 或MinHeight 来解决您的小窗口问题。

    【讨论】:

      猜你喜欢
      • 2010-11-08
      • 2018-11-25
      • 2011-07-22
      • 2013-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-17
      相关资源
      最近更新 更多