2014-09-25 2 views
0

WPF 및 C#을 사용하여 응용 프로그램을 개발하고 있습니다.WPF XAML DataTemplate 여러 항목을 자식으로 사용

나는 그것을 매력 있지만, 같은 작품이 StackPanel의에 ArchiveDateResultItem를 추가 할 때

내 문제는, ArchiveDateResultItem이 ArchiveColorItem의 목록이 포함되어 있습니다. StackPanel에가 일부 사용자 지정 컨트롤을 표시했습니다 내가 추가 할 그 여러 번이 StackPanel의 내부에 WrapPanel에 ArchiveColorItem (당신은 "내용이 여기에 올 것이다"아래의 XAML 코드에서 텍스트 볼 수 있습니다.

<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" VerticalAlignment="Top" x:Name="spp"> 
      <StackPanel.Resources> 
       <Style TargetType="{x:Type loc:ArchiveDateResultItem}"> 
        <Setter Property="Template"> 
         <Setter.Value> 
          <ControlTemplate> 
           <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,5,5"> 
            <StackPanel Orientation="Vertical"> 
             <Image Width="270" Height="130" VerticalAlignment="Top" HorizontalAlignment="Left" Source="silinecek/mrseb-windows-8-metro-start-screen_25.gif" Margin="0,0,2,0"/> 
             <StackPanel Orientation="Horizontal"> 
              <Label Content="{Binding Path=DesignName, RelativeSource={RelativeSource Mode=TemplatedParent}}" Foreground="White" HorizontalAlignment="Left" Width="157"/> 
              <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Width="112"> 
               <Label Content="{Binding Path=ChannelCount, RelativeSource={RelativeSource Mode=TemplatedParent}}" Foreground="White" Padding="0,5"/> 
               <Label Content=" CH," Foreground="White" Padding="0,5"/> 
               <Label Content="{Binding Path=VariantCount, RelativeSource={RelativeSource Mode=TemplatedParent}}" Foreground="White" Padding="0,5"/> 
               <Label Content=" MH" Foreground="White" Padding="0,5"/> 
              </StackPanel> 
             </StackPanel> 
            </StackPanel> 
            <ScrollViewer Tag="clrWrp" Width="174" Height="154" Template="{DynamicResource AppleStyleScrollBarStyle}" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Visible"> 
             <WrapPanel Orientation="Horizontal" Width="156" DataContext="{Binding Path=ResultColors}"> 
              <WrapPanel.Resources> 
               <Style TargetType="{x:Type loc:ArchiveColorItem}"> 
                <Setter Property="Template"> 
                 <Setter.Value> 
                  <ControlTemplate> 
                   <Border BorderThickness="1" BorderBrush="Black" Width="37" Height="37" Margin="2,0,0,2"> 
                    <Border BorderThickness="1" BorderBrush="White"> 
                     <Rectangle Fill="{Binding Path=ColorBrush}"></Rectangle> 
                    </Border> 
                   </Border> 
                  </ControlTemplate> 
                 </Setter.Value> 
                </Setter> 
               </Style> 
              </WrapPanel.Resources> 
              *****loc:ArchiveColorItem CONTENT SHOULD COME HERE***** 
             </WrapPanel> 
            </ScrollViewer> 
           </StackPanel> 
          </ControlTemplate> 
         </Setter.Value> 
        </Setter> 
       </Style> 
      </StackPanel.Resources> 

수업 내용은 다음과 같습니다 :

public class ArchiveDateResultItem : Control 
{ 
    public String DesignName { get; set; } 
    public String VariantCount { get; set; } 
    public String ChannelCount { get; set; } 

    private ArchiveColorItemCollection _resultColors = new ArchiveColorItemCollection(); 
    public ArchiveColorItemCollection ResultColors 
    { 
     get 
     { 
      return _resultColors; 
     } 
    } 
} 

public class ArchiveColorItemCollection : List<ArchiveColorItem> 
{ 
} 

public class ArchiveColorItem : Control 
{ 
    public SolidColorBrush ColorBrush { get; set; } 
} 

그리고이 내용을 화면에 추가하는 것은 내 XAML 코드입니다.

<loc:ArchiveDateResultItem DesignName="Try ME!" ChannelCount="20" VariantCount="20"> 
        <loc:ArchiveDateResultItem.ResultColors> 
         <loc:ArchiveColorItem ColorBrush="Red"></loc:ArchiveColorItem> 
         <loc:ArchiveColorItem ColorBrush="Red"></loc:ArchiveColorItem> 
         <loc:ArchiveColorItem ColorBrush="Red"></loc:ArchiveColorItem> 
        </loc:ArchiveDateResultItem.ResultColors> 
       </loc:ArchiveDateResultItem> 

나는이 줄을 추가

는 ArchiveDateResultItems가 화면에 표시되어 있지만, 나는 ArchiveColorItem를 볼 수 없습니다.

도와 주실 수 있습니까?

답변

0

ScrollViewer 대신 WrapPanel을 사용하고 ItemsControl을 사용하고 사용자 정의하십시오. 이 같은 것을 시도하십시오

<ItemsControl ItemsSource="{Binding Path=ResultColors}"> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <WrapPanel /> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
    <ItemsControl.ItemTemplate> 
     <DataTemplate> 
      <Border BorderThickness="1" BorderBrush="Black" Width="37" Height="37" Margin="2,0,0,2"> 
       <Border BorderThickness="1" BorderBrush="White"> 
        <Rectangle Fill="{Binding Path=ColorBrush}" /> 
       </Border> 
      </Border> 
     </DataTemplate> 
    </ItemsControl.ItemTemplate> 
</ItemsControl> 
+0

아직도 작동하지 않습니다. ScrollViewer 및 WrapPanel을 제거하고 조금 수정하여 코드를 추가했습니다. 하지만 결과는 같습니다. ( 그런데 답을 보내 주셔서 감사합니다. – cKNet