2012-06-26 5 views
1

나는 분명히 뭔가를 놓치고 있다고 생각합니다 ... Telerik Rad 컨트롤을 WPF 용으로 사용하고 있지만 서식있는 텍스트 상자에서 비슷한 구현을 사용한다고 가정합니다 병합 기능.Telerik 메일 병합 - 친숙한 이름 (RadRichTextBox 사용)

나는 나의 편지 병합 필드에 대한 몇 가지 쉬운 이름을 갖고 싶어. (필드 이름에, 즉 공간) 그래서 내가 예를

Public Class someclass 
{ 
<DisplayName("This is the complex description of the field")> 
Public property thisfieldnamehasacomplexdescription as string 

Public property anothercomplexfield as string 
} 

이 내가 편지 병합있는 드롭 다운에서 "친숙한"이름을 얻을 알고있는 유일한 방법에 대한 클래스가 있습니다. 이 "anothercomplexfield" "이 분야의 복잡한 설명은"

있지만 병합을 할 경우에만 anothercomplexfield 실제로 데이터로 채 웁니다 그래서 두 개의 필드로 괜찮 출현.

는 내가 편지 병합 필드를 보유하고있는 raddropdownbutton를 템플릿해야하는 건가? 여기에 대한 예가 있습니까?

하위 질문입니다. 어떻게 이러한 것들에 스크롤바를 추가합니까?

(또한 내가이 보드는 TELERIK 특정 보드 (대만족!) 아니라는 것을 알고 있지만, 이것은 미래의 누군가에게 유용 할 수 있습니다. 그래서 내가 여기에 Telerik에서 얻을 답을 복사 할 수 있습니다! http://www.telerik.com/community/forums/wpf/richtextbox/558428-radrichtextbox-mailmerge---using-displayname-to-create-a-friendly-name-with-spaces.aspx)

답변

0

이것은 telerik이 준 것입니다 :

기본 MergeFields에서는보다 친숙한 모양을 만들기 위해 필드의 표시 이름 부분을 변경할 수 없습니다. MergeField 클래스에서 파생하여 사용자 지정 MergeField를 구현하는 경우이 작업이 가능해야합니다. 다음은이 작업을 수행 할 수있는 방법을 보여주는 샘플 구현 :

public class CustomMergeField : MergeField 
{ 
private const string CustomFieldName = "CustomField"; 

static CustomMergeField() 
{ 
    CodeBasedFieldFactory.RegisterFieldType(CustomMergeField.CustomFieldName,() => { return new CustomMergeField(); }); 
} 

public override string FieldTypeName 
{ 
    get 
    { 
     return CustomMergeField.CustomFieldName; 
    } 
} 

public override Field CreateInstance() 
{ 
    return new CustomMergeField(); 
} 

protected override DocumentFragment GetDisplayNameFragment() 
{ 
    return base.CreateFragmentFromText(string.Format(Field.DisplayNameFragmentFormat, this.GetFriendlyFieldName(this.PropertyPath))); 
} 

private string GetFriendlyFieldName(string fieldName) 
{ 
    int lettersInEnglishAlphabet = 26; 
    List<char> separators = new List<char>(lettersInEnglishAlphabet); 
    for (int i = 0; i < lettersInEnglishAlphabet; i++) 
    { 
     separators.Add((char)('A' + i)); 
    } 
    StringBuilder newFieldName = new StringBuilder(); 
    int previousIndex = 0; 
    for (int i = 1; i < fieldName.Length; i++) 
    { 
     if (separators.Contains(fieldName[i])) 
     { 
      if (previousIndex > 0) 
      { 
       newFieldName.Append(" "); 
      } 
      newFieldName.Append(fieldName.Substring(previousIndex, i - previousIndex)); 
      previousIndex = i; 
     } 
    } 
    newFieldName.Append(" " + fieldName.Substring(previousIndex)); 
    return newFieldName.ToString(); 
} 
} 

참고 그 DisplayMode를 코드를 변경할 수 없습니다 때 표시되는 조각.

다른 질문으로, 드롭 다운 버튼의 내용을 변경하여 필드의 이름을 표시하고 스크롤 막대를 다음과 같이 포함 할 수 있습니다. 1. 먼저 버튼의 바인딩을 제거합니다 XAML에서 InsertMergeFieldEmptyCommand를 가져 와서 이름을 지정합니다 (예 : insertMergeField). 2. 다음으로, 코드 숨김에 다음 코드를 추가합니다

AddMergeFieldsInDropDownContent(this.insertMergeFieldButton); 

private void AddMergeFieldsInDropDownContent(RadRibbonDropDownButton radRibbonDropDownButton) 

{ 그리드 그리드 = 새로운 그리드(); grid.RowDefinitions.Add (새 RowDefinition() {높이 = 새 GridLength (100, GridUnitType.Pixel)});

ScrollViewer scrollViewer = new ScrollViewer(); 
scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; 
StackPanel stackPanel = new StackPanel(); 

foreach (string fieldName in this.editor.Document.MailMergeDataSource.GetColumnNames()) 
{ 
    RadRibbonButton fieldButton = new RadRibbonButton() 
    { 
     Text = this.GetFriendlyFieldName(fieldName), 
     Size = ButtonSize.Medium, 
     HorizontalAlignment = HorizontalAlignment.Stretch, 
     HorizontalContentAlignment = HorizontalAlignment.Left 
    }; 

    fieldButton.Command = this.editor.Commands.InsertFieldCommand; 
    fieldButton.CommandParameter = new MergeField() { PropertyPath = fieldName }; 
    //or 
    //fieldButton.CommandParameter = new CustomMergeField() { PropertyPath = fieldName }; 

    stackPanel.Children.Add(fieldButton); 
} 
stackPanel.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; 
scrollViewer.Content = stackPanel; 
grid.Children.Add(scrollViewer); 

radRibbonDropDownButton.DropDownContent = grid; 
} 

당신은 물론 GetFriendlyName 방법의 코드를 최적화하고 두 클래스로 사용할 수있는 방법으로 추가 할 수 있습니다.

관련 문제