WPF绑定中的默认值 [英] Default value in WPF Binding

查看:172
本文介绍了WPF绑定中的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经绑定了我的窗口的 Height Width 。现在,Visual Studio中的窗口很小,我不能再工作了。将默认值设置为高度宽度可以解决我的问题。是否可以在绑定

I've bound the Height and Width of my window. Now, the window is so tiny in Visual Studio I can't work on it anymore. Setting default values to Height and Width would solve my problem. Is it possible in 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中设置默认值绑定 ?如何?

Can we set default values in WPF Binding? How?

推荐答案

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

You might also be able to use MinWidth or MinHeight to address your small window issue.

这篇关于WPF绑定中的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆