3

My CustomControls UI element Visibility is bound through a BoolToVisibilityConverter, see code below :

<cc:CustomFFU LabelText="FFUZoneF_2-1"  HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="2" Grid.Column="1" Width="55" Height="35" 
        InstanceAddress="MCS1.Cleanroom.ProcessCell.UN_ZonesF.EM_FFU.CM_FFU2_1" 
        Visibility="{Binding VisibilityFFUView, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource BoolToVisibilityConverter}}" />

The code works as it should, however during design-time the visibility is Collapsed. So every CustomControl on my window is not visible during development. Quite annyoning..

How is the visibility during design-time fixed to Visibility? Ps. when I delete the BoolToVisibilityConverter, the status changes from Collapsed to Visible? Perhaps, because when designing the value represent false. Just a guess.

3

2 Answers 2

4

If you are using Visual Studio, you should add d:Visibility="Visible" property in xaml element that you want to be visible in design time

like this:

<Button Visibility="{Binding Property}" d:Visibility="Visible" />

and make sure that you have Ignorable="d" from "http://schemas.openxmlformats.org/markup-compatibility/2006" namespace on your root xaml element like this:

<Window x:Class="WpfApp2.MainWindow"
                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:local="clr-namespace:WpfApp2"
add this --->   xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
and this --->   mc:Ignorable="d"
                Title="MainWindow" Height="450" Width="800">
    <Grid>
    </Grid>
</Window>

This doesn't work in Rider wpf designer

10
  • 1
    Thanks for your answer. The following error occors when I add the d:Visibility. The property "Visibility" does not exist in the "schemas.microsoft.com/expression/blend/2008" namespace.
    – AfronSall
    Commented May 12, 2022 at 20:45
  • 1
    Thanks again. I already had both integrated, but still receiving the same error message. I'm using Visual Studio 2019.
    – AfronSall
    Commented May 13, 2022 at 8:20
  • 1
    d:IsHidden="False" is working. However, the object is still collapsed ofcourse. d:Visibility="Visible" doesn't seem to exists in Blend? Do you have a working sample?
    – AfronSall
    Commented May 17, 2022 at 8:54
  • 1
    @AfronSall yes here it is github.com/U7nk/d-Visibility-example/tree/main tested with visual studio 2019 community 16.11.14 Commented May 17, 2022 at 13:28
  • 2
    @AfronSall looks like d:Visibility is not supported at net framework, but you can use another approach. Here is example for net framework 4.6.1 (working poorly on visual studio 2022, vs 19 is ok ) github.com/U7nk/d-Visibility-example/tree/main/… i will add it to answer later Commented May 18, 2022 at 13:09
1

I Found the way to solve “why vs2019 can't use d:Visibility directly”. This is microsoft answer: https://learn.microsoft.com/en-us/visualstudio/xaml-tools/xaml-designtime-data?view=vs-2019#troubleshooting

  1. Design-time data requires Visual Studio 2019 version 16.7 or later.
  2. Supports Windows desktop projects that target Windows Presentation Foundation (WPF) for .NET Core and UWP. This feature is also available for .NET Framework in the Preview channel. To enable it, go to Tools > Options > Environment > Preview Features, select New WPF XAML Designer for .NET Framework and then restart Visual Studio.

When I selected New WPF XAML Designer for .Net Framework, I can use d:Visibilty and I haven't seen the error again!

Not the answer you're looking for? Browse other questions tagged or ask your own question.