public void CtxmGenerateRestoreMenuItems(MenuItem menu) { //クリア object menuReset = menu.Items[menu.Items.Count - 1]; menu.Items.Clear(); for (int i = 0; i < CmdHistorys.Count; i++) { List <IRecWorkMainData> list = CmdHistorys.Historys[i].Items; var menuItem = new MenuItem(); var s = string.Format((CmdHistorys.Historys[i].Command == EpgCmds.Delete ? "削除した{0}を復元" : "変更前の{0}を新規追加") + "(_{1}) : {2}" , new InfoSearchItem(list[0]).ViewItemName, ToAccessKey(i, 16), MenuUtil.ToAccessKeyForm(ToMenuString(list[0]))) + (list.Count > 1 ? " ほか" + (list.Count - 1) : ""); menuItem.Header = CommonUtil.LimitLenString(s, 45, 31); // 長すぎる場合は省略 if (list.Count >= 2 || (menuItem.Header as string).Length != s.Length) { s = string.Join("\r\n", list.Take(10).Select(item => ToMenuString(item))) + (list.Count > 10 ? "\r\nほか" + (list.Count - 10) : ""); menuItem.ToolTip = ViewUtil.GetTooltipBlockStandard(s); } menuItem.Command = EpgCmds.RestoreItem; menuItem.CommandParameter = new EpgCmdParam(menu.CommandParameter as EpgCmdParam); (menuItem.CommandParameter as EpgCmdParam).ID = i; menuItem.Tag = menuItem.Command; menu.Items.Add(menuItem); } menu.IsEnabled = menu.Items.Count > 0; menu.Items.Add(new Separator()); menu.Items.Add(menuReset); }
/// <summary>長すぎるとき省略してツールチップを追加する</summary> public void SetLimitLenHeader(MenuItem menu, string s, bool?useTextBlock, int max = 45, int pos = -1) { s = s ?? menu.Header as string; if (s != null && s.Length > max) { menu.ToolTip = ViewUtil.GetTooltipBlockStandard(s); s = CommonUtil.LimitLenString(s, max, pos); // 長すぎる場合は省略 } menu.Header = useTextBlock == null ? s : useTextBlock == true ? (object)new TextBlock { Text = s, Tag = s } : new Label { Content = s, Padding = new Thickness(), Tag = s }; }
/// <summary>長すぎるとき省略してツールチップを追加する</summary> public bool LimitLenHeader(MenuItem menu, int max = 45, int pos = -1) { var header = menu.Header as string; if (header == null) { return(false); } bool isLengthOver = header.Length > max; if (isLengthOver == true) { menu.ToolTip = ViewUtil.GetTooltipBlockStandard(header); header = CommonUtil.LimitLenString(header, max, pos); // 長すぎる場合は省略 } menu.Header = header; return(isLengthOver); }