トグルボタンには以下のスタイルがあります。
<Style x:Key="SearchDataControlStyle" TargetType="{x:Type ToggleButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate >
<Grid x:Name="grd" Height="80" Width="120" Margin="5">
<Rectangle x:Name="baseColor" RadiusY="15" RadiusX="15" Fill="{TemplateBinding Background}"/>
<Rectangle x:Name="Glow" RadiusY="15" RadiusX="15" Opacity="0">
<Rectangle.Fill>
<RadialGradientBrush GradientOrigin="0.505,1.291" RadiusY="0.853" RadiusX="0.853">
<GradientStop Color="Black"/>
<GradientStop Color="White" Offset="1"/>
<GradientStop Color="#FF00BBFF"/>
<GradientStop Color="#FF939393" Offset="1"/>
<GradientStop Color="#00C1C1C1" Offset="0.996"/>
<GradientStop Color="#A5A4E0EB" Offset="0.28"/>
<GradientStop Color="#53818AD5" Offset="0.543"/>
<GradientStop Color="#7C92B5E0" Offset="0.453"/>
</RadialGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle x:Name="Glass" RadiusY="15" RadiusX="15" Opacity="0.8">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.514,1.158" StartPoint="0.514,-0.101">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="White" Offset="1"/>
<GradientStop Color="Black" Offset="0.149"/>
<GradientStop Color="#FFABABAB" Offset="1"/>
<GradientStop Color="#FF7A7A7A" Offset="0.414"/>
<GradientStop Color="#FF909090" Offset="0.61"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<StackPanel Orientation="Horizontal">
<Image x:Name="imgDependent" Visibility="Visible" Source="D:\Elektra Main\SearchPanel\DynamicSearchPanel\SearchProvider\Dependent.png" HorizontalAlignment="Left" Height="20" Width="20" Margin="3" VerticalAlignment="Top" />
<Image x:Name="imgOptional" Visibility="Visible" Source="D:\Elektra Main\SearchPanel\DynamicSearchPanel\SearchProvider\Optional.png" HorizontalAlignment="Left" Height="20" Width="20" Margin="3" VerticalAlignment="Top" />
</StackPanel>
<ContentPresenter Content="{Binding Description}" VerticalAlignment="Center" HorizontalAlignment="Center" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Control.IsMouseOver" Value="True">
<Setter TargetName="Glow" Property="Opacity" Value="0.8" />
</Trigger>
<Trigger Property="ToggleButton.IsChecked" Value="True">
<Setter TargetName="baseColor" Property="Fill" Value="Black" />
</Trigger>
<DataTrigger Binding="{Binding IsDependentElement}" Value="{x:Null}" >
<Setter TargetName="imgDependent" Property="Visibility" Value="Collapsed"/>
</DataTrigger>
<DataTrigger Binding="{Binding IsOptionalElement}" Value="{x:Null}" >
<Setter TargetName="imgOptional" Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Control.Foreground" Value="White" />
</Style>
質問は、Togglebutton DataContext は、プロパティ IsOptionalElement および IsDependentElement を持つカスタム クラスです。動作していない 2 つのデータトリガーを設定しましたか?
public class SearchData
{
public string FieldName { get; set; }
public string Description { get; set; }
public SearchDataType Type { get; set; }
public string Validator { get; set; }
public object DefaultValue { get; set; }
public object SelectedValue { get; set; }
public Dictionary<string, object> ComboBoxItemSource
{
get;
set;
}
public int DefaultSelectedIndex { get; set; }
public bool IsYesOrNo { get; set; }
public OnValidateText OnValidate { get; set; }
public string OptionalElement { get; set; }
public string DependentElement { get; set; }
public bool IsDisplayed { get; set; }
public bool HasValue { get; set; }
}