在ContextMenu中折叠TextBlock

时间:2016-08-04 19:29:00

标签: c# wpf

目前我对所有RadMenuItems都有条件可见性。如果所选项目处于活动状态,则显示全部RadMenuItems,否则隐藏一些。我可以毫无问题地成功崩溃MenuItems。在我的ContextMenus中我有菜单项和一些标题文本块。菜单项完全折叠,折叠时的文本块留下一个空白区域,该区域仍然是高亮显示的。

我想知道如何在TextBlock内折叠内部ContextMenu或在上下文菜单中显示标题的正确方法

<telerik:RadContextMenu 
    <telerik:RadMenuItem Header="New Appointment"/>

    <telerik:RadMenuItem Header="Delete Appointment"
                         Visibility="{Binding SelectedAppointment.ContextVisible, Converter={StaticResource BooleanToVisibilityConverter}}"/>

    <TextBlock           Text="Time Markers"
                         Visibility="{Binding SelectedAppointment.ContextVisible, Converter={StaticResource BooleanToVisibilityConverter}}"/>

    <telerik:RadMenuItem Header="Move Appointment"
                         Visibility="{Binding SelectedAppointment.ContextVisible, Converter={StaticResource BooleanToVisibilityConverter}}"/>
/>

转换器

public class BoolToVisibilityConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return (bool) value ? Visibility.Visible : Visibility.Collapsed;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

尝试将文本块包装在如下所示的堆栈面板周围并具有相同的结果

<StackPanel    Visibility="{Binding SelectedAppointment.ContextVisible, Converter={StaticResource BooleanToVisibilityConverter}}"> 
    <TextBlock    Text="Time Markers"/>
</StackPanel>

0 个答案:

没有答案