Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default value in WPF Binding

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>

Can we set default values in WPF Binding? How?

like image 486
Mohammad Dayyan Avatar asked Feb 10 '10 17:02

Mohammad Dayyan


1 Answers

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

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

like image 153
kenwarner Avatar answered Sep 30 '22 22:09

kenwarner