2017-01-31 1 views
1

저는 wpf와 mvvm이 새롭기 때문에 약간의 도움을 요청했습니다. 미안하지만 영어가 제 모국어가 아닙니다. 일부 문서를 표시하는 주 응용 프로그램이 있습니다. 각 문서는 데이터가있는 외부 dll + xml 파일입니다. 은 ContentControl에서두 개의 다른 라이브러리에있는 ScrollViewer 내의 Wrappanel

<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Background="DarkGray"> 
    <Border Margin="20" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="White" Padding="20"> 
    <ContentControl x:Name="ccCurrentView" cal:View.Model="{Binding Path=CurrentView}"/>     
    </Border> 
</ScrollViewer> 

내가 DLL에서 UserControl을 같은 내 문서보기를 표시 : 기본 응용 프로그램에서

은 내가 XAML 있습니다. 그리고 우리는 MVVM을 사용하므로 문서의 XAML은 같은 것입니다 :
<UserControl> 
    <StackPanel> 
    <UserControl_Type1 /> 
    <UserControl_Type2 />... 
    </StackPanel> 
    <UserControl_Type3 /> 
</UserControl> 

이 UserControl_TypeXXX의 모든

가 자신의 DLL 내부 될 수 있습니다.

이제 사용자가 일부 유형의 UserControl에 대해 StackPanel을 WrapPanel로 교체하라고합니다. 그리고 사용자가 주요 응용 프로그램의 크기를 조정할 때, 일부 컨트롤은 먼저 자신의 요소를 래핑 한 다음 모든 문서에 대한 스크롤 막대 만 표시합니다. 하지만 내가 읽은 정보에 따르면 WrapPanel은 ScrollViewer를 래핑하지 않습니다.

주 응용 프로그램에서 widht 및 height가없고 자신의 문서에서 어떤 UserControl이 해당 요소를 래핑해야하는지 예측할 수 없으면 어떻게해야합니까?

답변

0

이 부분은 article about xaml anti-patterns이며, 많은 도움이됩니다.
제 경우에는 두 개의 콘텐츠 템플릿 사이를 전환합니다. 하나는 오래된 문서 용 ScrollViewer이고, 다른 하나는없는 것입니다. 자료에
: MainPanel에서

 <DataTemplate x:Key="ResizableContent" > 
      <Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="DarkGray"> 
       <Border Margin="20" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="White" Padding="20"> 
        <ContentControl x:Name="ccCurrentView" cal:View.Model="{Binding Path=CurrentView}"/> 
       </Border> 
      </Border> 
     </DataTemplate> 
     <DataTemplate x:Key="NotResizableContent" > 
      <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Background="DarkGray"> 
       <Border Margin="20" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="White" Padding="20"> 
        <ContentControl x:Name="ccCurrentView" cal:View.Model="{Binding Path=CurrentView}"/> 
       </Border> 
      </ScrollViewer> 
     </DataTemplate> 

:

<ContentControl Content="{Binding}"> 
     <ContentControl.Style> 
      <Style TargetType="{x:Type ContentControl}"> 
       <Setter Property="ContentTemplate" Value="{StaticResource NotResizableContent}" /> 
       <Style.Triggers> 
        <DataTrigger Binding="{Binding Path=IsResizable}" Value="True"> 
         <Setter Property="ContentTemplate" Value="{StaticResource ResizableContent}" /> 
        </DataTrigger> 
       </Style.Triggers> 
      </Style> 
     </ContentControl.Style> 
    </ContentControl> 
관련 문제