Comment puis-je passer un TextBlock de la visibilité dans un DataTrigger?
Ce code œuvres (quand ControlType="liste déroulante", puis de l'arrière-plan jaune):
<Window x:Class="TestCollapsed.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="clr-namespace:TestCollapsed.Commands"
Title="Main Window" Height="400" Width="800">
<Window.Resources>
<Style x:Key="DropDownStyle" TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding ControlType}" Value="dropDown">
<Setter Property="Background" Value="Yellow"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<TextBlock Visibility="Visible"
Text="This is going to be the dropdown control."
Style="{StaticResource DropDownStyle}"/>
</StackPanel>
</Window>
Mais ce code ne pas travail (quand ControlType="liste déroulante", puis le TextBlock est encore invisible):
<Window x:Class="TestCollapsed.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="clr-namespace:TestCollapsed.Commands"
Title="Main Window" Height="400" Width="800">
<Window.Resources>
<Style x:Key="DropDownStyle" TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding ControlType}" Value="dropDown">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<TextBlock Visibility="Collapsed"
Text="This is going to be the dropdown control."
Style="{StaticResource DropDownStyle}"/>
</StackPanel>
</Window>
Pourquoi je ne peux pas définir la visibilité dans un style que je puisse en arrière-plan?
Vous devez vous connecter pour publier un commentaire.
De la configuration de la Visibilité sur le TextBlock et ensuite essayer de le remplacer avec un style. Cela ne marchera pas. Essayez ceci:
J'ai le même problème. @Bryan réponse est parfait!
Il y a le mal et le droit à des versions.
La mauvaise version:
La bonne version: