ドロップダウンとグリッドがあります。グリッド列にハイパーリンクがあります。ドロップダウン コレクションに 1 つの項目が含まれている場合、ドロップダウンは非表示にする必要があります。つまり、項目のコレクションに対して可視性をバインドするロジックが必要です。
GRid 内の 1 つのハイパーリンクの XAML を次に示します。
<!--Associate-->
<TextBlock Margin="10, 0, 0, 0">
<TextBlock.Visibility>
<MultiBinding Converter="{StaticResource courseListVisibilityConverter}"
ConverterParameter="Associate">
<Binding Path="IsCourseAssocited"
RelativeSource="{RelativeSource Mode=FindAncestor,AncestorType={x:Type DPA2:TakenCoursesNotApplied}}" />
<Binding Path="DataContext"
RelativeSource="{RelativeSource Self}" />
</MultiBinding>
</TextBlock.Visibility>
<Hyperlink DataContext="{Binding}"
Name="Associate"
IsEnabled="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TextBlock}}, Path=IsVisible}"
Click="Associate_Click">
<TextBlock TextWrapping="Wrap"
Text="Associate" />
</Hyperlink>
</TextBlock>
public class CourseListVisibilityConverter : IMultiValueConverter
{
public object Convert(object[] value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null || value[0] == null || value[1] == null) return Visibility.Collapsed;
bool IsEditMode = value[0] == DependencyProperty.UnsetValue ? false : (bool)value[0];
if (value[1].GetType() == typeof(Course))
{
Course course = value[1] as Course;
if (course == null) return string.Empty;
//Visibility retVal = Visibility.Visible;
switch (parameter.ToString())
{
case "CodeLink":
if (!IsEditMode) return Visibility.Collapsed;
if (course.HideOptions) return Visibility.Collapsed;
if (course.IsInElectivePool &&
course.IsManualAdd) return Visibility.Visible;
if (!course.IsInElectivePool &&
!course.IsWaived) return Visibility.Visible;
if (course.IsInElectivePool &&
course.FulFillmentId != 0 &&
course.FulFillmentId != -1 &&
!course.IsWaived) return Visibility.Visible;
return Visibility.Collapsed;
case "CodeNoLink":
if (!IsEditMode) return Visibility.Visible;
if (course.HideOptions) return Visibility.Visible;
if (course.IsInElectivePool &&
course.IsManualAdd) return Visibility.Collapsed;
if (!course.IsInElectivePool &&
!course.IsWaived) return Visibility.Collapsed;
if (course.IsInElectivePool &&
course.FulFillmentId != 0 &&
course.FulFillmentId != -1 &&
!course.IsWaived) return Visibility.Collapsed;
return Visibility.Visible;
case "Waive":
if (course.HideOptions) return Visibility.Collapsed;
if (IsEditMode &&
!course.IsWaived &&
!(course.RetakenFlag == RetakeFlagType.RetakeOfCourse) &&
!course.IsInElectivePool) return Visibility.Visible;
return Visibility.Collapsed;
case "UndoWaive":
if (course.HideOptions) return Visibility.Collapsed;
if (IsEditMode && course.IsWaived &&
!(course.RetakenFlag == RetakeFlagType.RetakeOfCourse) &&
!course.IsInElectivePool) return Visibility.Visible;
return Visibility.Collapsed;
case "UndoAdd":
if (course.HideOptions) return Visibility.Collapsed;
if (IsEditMode && course.IsManualAdd &&
(!(course.RetakenFlag == RetakeFlagType.RetakeOfCourse) &&
!course.IsInElectivePool)) return Visibility.Visible;
return Visibility.Collapsed;
case "Associate":
if (course.HideOptions) return Visibility.Collapsed;
if (IsEditMode && course.IsCourseAssocited)
return Visibility.Collapsed;
else if (IsEditMode &&
((course.Status.ToUpper() == "COMPLETE" || course.Status.ToUpper() == "DROPPED")))
{
return Visibility.Visible;
}
else
{
return Visibility.Collapsed;
}
//case "UnAssociate":
// if (course.HideOptions) return Visibility.Collapsed;
// if (IsEditMode && (course.IsCourseAssocited))
// {
// return Visibility.Visible;
// }
// else
// {
// return Visibility.Collapsed;
// }
case "FullFillRequirement":
if (course.HideOptions) return Visibility.Collapsed;
if (IsEditMode &&
((course.Status.ToUpper() == "FUTURE")))
{
return Visibility.Visible;
}
else
{
return Visibility.Collapsed;
}
default:
return Visibility.Collapsed;
}
}
else if (value[1].GetType() == typeof(ElectivePool))
{
ElectivePool electivePool = value[1] as ElectivePool;
if (electivePool == null) return string.Empty;
switch (parameter.ToString())
{
case "Waive":
if (IsEditMode &&
!electivePool.IsWaived) return Visibility.Visible;
return Visibility.Collapsed;
case "UndoWaive":
if (IsEditMode &&
electivePool.IsWaived) return Visibility.Visible;
return Visibility.Collapsed;
}
}
return Visibility.Visible;
}
public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}