Dot-Net

WPF 綁定中的預設值

  • November 6, 2016

我已經綁定了我的視窗的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嗎?如何?

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解決您的小視窗問題。

引用自:https://stackoverflow.com/questions/2238905