У меня есть UIElement с несколькими Canvas, которые я хочу показать или скрыть в зависимости от определенных обстоятельств.Я хочу, чтобы это было видно как в дизайнере, так и во время работы программы.Я пробовал несколько привязок, а также BooleanToVisibilityConverter.Но я застрял и не могу найти свою ошибку.Итак, вот код:
UIElement (только с двумя Canvas; я получил отвечающие свойства в частичном классе)
<component:AbstractComponent x:Class="View.LineComponent"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:component="clr-namespace:View"
x:Name="userControl" Width="70" Height="10"
>
<component:AbstractComponent.Resources>
<BooleanToVisibilityConverter x:Key="VisibilityConverter" />
</component:AbstractComponent.Resources>
<Canvas Width="{Binding ElementName=userControl, Path=ActualWidth}">
<Canvas Name="Line"
Height="{Binding ElementName=userControl, Path=ActualHeight}"
Width="{Binding ElementName=userControl, Path=ActualWidth}"
Visibility="{Binding LineVisible, Converter={StaticResource VisibilityConverter}, FallbackValue=Hidden}"
>
<!-- Lot of stuff; Not interesting for the question-->
</Canvas>
<Canvas Name="Arrow"
Height="{Binding ElementName=userControl, Path=ActualHeight, TargetNullValue=6.397, FallbackValue=6.397}"
Width="{Binding ElementName=userControl, Path=ActualWidth, TargetNullValue=16.688, FallbackValue=16.688}"
Visibility ="{Binding ArrowVisible, Converter={StaticResource VisibilityConverter}, FallbackValue=Hidden}"
>
<!-- Lot of stuff; Not interesting for the question-->
</Canvas>
</Canvas>
</component:AbstractComponent>
Использование в ParentWindow
<component:LineComponent Height="50" Canvas.Top="100" Width="50" Canvas.Left="50" LineVisible="True"/>
<component:LineComponent Height="50" Canvas.Top="200" Width="50" Canvas.Left="50" ArrowVisible="True"/>
Я ожидаю, что в первом случае отображается Line
-Канва, а в другом - Arrow
-Канва.Они оба остаются Hidden
хотя.Я также попробовал другой подход, объявив свойства LineVisible
и ArrowVisible
непосредственно в C # -Code, но это тоже не сработало.Есть идеи?