2009-10-23 4 views
3

을 바인딩 항목을 반복 : 대신의 DataContext에게 제목 및 AssignedTo 속성 클래스를주는 I는 다음과 같습니다 WPF에서 flowdocument이 WPF에서 FlowDocument

<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <Paragraph FontFamily="Georgia"> 
     <StackPanel> 
      <TextBlock Text="{Binding Path=Title}"/> 
      <TextBlock Text="{Binding Path=AssignedTo}"/> 
     </StackPanel> 
    </Paragraph> 
</FlowDocument> 

가, 내가 좋아하는 것

그것을의 목록을 제공 그 클래스와 flowdocument 그들 각각의 개체를 보여줍니다. 누군가가이 일을하기 위해 flowdocument에 XAML을 어떻게 형성하는지 말해 줄 수 있습니까?

+0

을 [이 질문의 중복 것 같아 여기에 스팬 제어와 작은 샘플입니다 ] (http://stackoverflow.com/questions/1254633/is-there-an-itemscontrol-equivalent-for-text-content/1258900#1258900) –

답변

8
당신을 위해 작동 어쩌면 다음 코드 샘플로 간단하게 알고

, Ajma : 당신은 건물 내부에 상상할 수있는 어떤

<Window x:Class="WpfTest.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:WpfTest="clr-namespace:WpfTest" 
    xmlns:System="clr-namespace:System;assembly=mscorlib" 
    xmlns:Collections="clr-namespace:System.Collections;assembly=mscorlib" 
    Title="Bound Inlines Sample" Height="300" Width="300"> 
    <Window.Resources> 
    <Collections:ArrayList x:Key="array"> 
     <System:String>Hello</System:String> 
     <System:String>World</System:String> 
     <System:String>!</System:String> 
    </Collections:ArrayList> 
    </Window.Resources> 
    <Grid> 
    <FlowDocumentReader> 
     <FlowDocument> 
     <Paragraph FontFamily="Georgia"> 
      <ItemsControl ItemsSource="{StaticResource array}"/>    
     </Paragraph> 
     </FlowDocument> 
    </FlowDocumentReader> 
    </Grid> 
</Window> 

그렇지 않은 경우, 당신은 항상 당신의 자신의 연결된 속성을 생성 할 수있는 변경 공고.

CS :

public class SpanOperations : DependencyObject 
{ 
    public static IEnumerable GetInlineSource(DependencyObject obj) 
    { 
    return (IEnumerable)obj.GetValue(InlineSourceProperty); 
    } 

    public static void SetInlineSource(DependencyObject obj, IEnumerable value) 
    { 
    obj.SetValue(InlineSourceProperty, value); 
    } 

    public static readonly DependencyProperty InlineSourceProperty = 
     DependencyProperty.RegisterAttached("InlineSource", typeof(IEnumerable), typeof(SpanOperations), new UIPropertyMetadata(null, OnInlineSourceChanged)); 

    private static void OnInlineSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
    { 
    var span = d as Span; 
    if (span == null) 
    { 
     // It's a demo only. Can work with only spans... 
     return; 
    } 
    span.Inlines.Clear(); 

    var inlines = e.NewValue as IEnumerable; 
    if (inlines != null) 
    { 
     foreach (var inline in inlines) 
     { 
     // We assume only inlines will come in collection: 
     span.Inlines.Add(inline as Inline); 
     } 

    } 
    } 
} 

XAML

<Window x:Class="WpfTest.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:WpfTest="clr-namespace:WpfTest" 
    xmlns:Collections="clr-namespace:System.Collections;assembly=mscorlib" 
    Title="Bound Inlines Sample" Height="300" Width="300"> 
    <Window.Resources> 
    <Collections:ArrayList x:Key="array"> 
     <Run>Hello</Run> 
     <LineBreak/> 
     <Run>Hello</Run> 
     <LineBreak/> 
     <Bold> 
     <Run>Hello</Run> 
     </Bold> 
    </Collections:ArrayList> 
    </Window.Resources> 
    <Grid> 
    <FlowDocumentReader> 
     <FlowDocument> 
     <Paragraph FontFamily="Georgia"> 
      <Span WpfTest:SpanOperations.InlineSource="{Binding Source={StaticResource array}}"/> 
     </Paragraph> 
     </FlowDocument> 
    </FlowDocumentReader> 
    </Grid> 
</Window> 

희망이 도움이 :)

+0

첨부 된 속성 규칙, 좋은 대답 Andrey! –