ComboBox の SelectedItem に基づいて GroupBox の Visibility プロパティをバインドしようとしています。コンボボックスが表示されますFreqTypeCollection
。対応する GroupBox を非表示/表示したいです。
public Dictionary<FreqType, string> FreqTypeCollection
{
get
{
var d =
new Dictionary<FreqType, string>()
{
{FreqType.OneTimeOnly, "One time only"},
{FreqType.Daily, "Recurring - Daily"},
{FreqType.Weekly, "Recurring - Weekly"},
{FreqType.Monthly, "Recurring - Monthly"},
{FreqType.MonthlyRelativeToFreqInterval, "Monthly relative"}
};
return d;
}
}
<ComboBox Name="ScheduleTypeComboBox" ItemsSource="{Binding Path=FreqTypeCollection}" DisplayMemberPath="Value"
SelectedValuePath="Key" SelectedValue="{Binding Path=freq_type, Mode=TwoWay, Converter={StaticResource FreqTypeConverter}}">
<GroupBox Header="One time only" Name="OneTimeOnlyGroupBox" Visibility="Collapsed">
<GroupBox.Style>
<Style TargetType="GroupBox">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=freq_type}" Value="1">
<Setter Property="Visibility" Value="Visible"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</GroupBox.Style>
</GroupBox>
<GroupBox Header="Recurring-Daily" Name="DailyGroupBox" Visibility="Collapsed">
<GroupBox.Style>
<Style TargetType="GroupBox">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=freq_type}" Value="2">
<Setter Property="Visibility" Value="Visible"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</GroupBox.Style>
</GroupBox>
class FreqTypeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null)
return null;
else
{
FreqType f = (FreqType)value;
return f;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
int rValue=(int)value;
return rValue;
}
}
public enum FreqType
{
[Display(Name = "One time only")]
[Description("Task will be scheduled one time only.")]
OneTimeOnly = 1,
[Display(Name = "Daily")]
[Description("Recurring daily.")]
Daily = 4,
[Display(Name = "Weekly")]
[Description("Recurring weekly.")]
Weekly = 8,
[Display(Name = "Monthly")]
[Description("Recurring monthly.")]
Monthly = 16,
[Display(Name = "Monthly relative")]
[Description("Recurring monthly relatively.")]
MonthlyRelativeToFreqInterval = 32,
};