0

I have Visibility bound to a bool, which works perfectly. However when editing the page the Border is not visible. I have to delete the Visibility Binding, make my changes and redo the Visibility Binding.

I'm pretty sure I saw there is a way to set a "editing default", but I cannot find that link anymore (or remember what it was called). Can someone explain how to set the default to visible so I can see it whilst editing, but not affect it's operation at runtime?

<Border Grid.Column="2" BorderBrush="HotPink" BorderThickness="2" MinHeight="100" MinWidth="100" 
                Visibility="{Binding ElementName=GenerateWorkOrders, Path=IsChecked, Converter={StaticResource booleanToVisibility}, UpdateSourceTrigger=PropertyChanged}">
            <Label Content="Not Visible While Editing"/>
        </Border>
mjordan
  • 319
  • 2
  • 22
  • by 'editing the page', did you mean when you are using Designer in Visual Studio? You may want to check this [answer](https://stackoverflow.com/a/21278611/587690) – Suresh Jun 12 '19 at 12:44
  • Generateworkorders is presumably unchecked by default. You could maybe set it checked or give it's ischecked a fallbackvalue value of true. – Andy Jun 12 '19 at 13:08
  • Yes Designer mode in VS and I believe FallbackValue is what I was looking for, but this doesn't seem to do anything: Visibility="{Binding ElementName=GenerateWorkOrders, Path=IsChecked, Converter={StaticResource booleanToVisibility}, UpdateSourceTrigger=PropertyChanged, FallbackValue=Visible}" . Am I doing something wrong? – mjordan Jun 12 '19 at 13:28
  • did you try `TargetNullValue` ? – Suresh Jun 12 '19 at 15:01
  • I am not familiar with it, but it looks interesting. Can you show how to use? – mjordan Jun 12 '19 at 15:06

1 Answers1

1

The problem is that the default value of IsChecked of GenerateWorkOrders CheckBox is false

If IsChecked have Binding, you can use FallbackValue:

<CheckBox x:Name="GenerateWorkOrders" IsChecked="{Binding SomeProperty, FallbackValue=True}" />

Another way is to avoid the binding, you can use the DesignerProperties.IsInDesignMode Attached Properties that indicate if you in design mode (More inforamtion).

You can use this property in behavior, or in XAML only approach:

    <Border Grid.Column="2" BorderBrush="HotPink" BorderThickness="2" MinHeight="100" MinWidth="100">
        <Border.Style>
            <Style TargetType="{x:Type Border}">
                <Setter Property="Visibility" Value="{Binding ElementName=GenerateWorkOrders, Path=IsChecked, Converter={StaticResource booleanToVisibilityConverter}, UpdateSourceTrigger=PropertyChanged}" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(componentModel:DesignerProperties.IsInDesignMode)}" Value="true">
                        <Setter Property="Visibility" Value="Visible" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Border.Style>
        <Label Content="Not Visible While Editing"/>
    </Border>
itaiy
  • 1,152
  • 1
  • 13
  • 22
  • Thank you! I put the FallbackValue on the wrong control... Instead of putting it on the checkbox (like you show) I was trying to put a FallbackValue in the Visibility property of the Border. – mjordan Jun 12 '19 at 16:47