2016-08-23 93 views
0

我在我的Windows XAMLItemsPresenter崩潰XAML設計

<TreeView Margin="3" ItemsSource="{Binding Path=Model.Files}" 
     TreeViewItem.Collapsed="TreeViewItem_OnCollapsed"> 
<TreeView.ItemContainerStyle> 
    <Style TargetType="TreeViewItem"> 
     <Setter Property="IsExpanded" Value="{Binding Path=IsExpanded}" /> 
     <Setter Property="IsSelected" Value="{Binding Path=IsSelected}" /> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="TreeViewItem"> 
        <Grid> 
         <Grid.ColumnDefinitions> 
          <ColumnDefinition Width="Auto" MinWidth="19" /> 
          <ColumnDefinition Width="Auto" /> 
          <ColumnDefinition Width="*" /> 
         </Grid.ColumnDefinitions> 
         <Grid.RowDefinitions> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
         </Grid.RowDefinitions> 
         <ToggleButton IsChecked="False" Visibility="Hidden" 
             ClickMode="Press" Name="Expander" /> 
         <Border 
          BorderThickness="{TemplateBinding Border.BorderThickness}" 
          Padding="{TemplateBinding Control.Padding}" 
          BorderBrush="{TemplateBinding Border.BorderBrush}" 
          Background="{TemplateBinding Panel.Background}" Name="Bd" 
          SnapsToDevicePixels="True" Grid.Row="0" Grid.Column="1"> 
          <ContentPresenter 
           Content="{TemplateBinding HeaderedContentControl.Header}" 
           ContentTemplate="{TemplateBinding HeaderedContentControl.HeaderTemplate}" 
           ContentStringFormat="{TemplateBinding HeaderedItemsControl.HeaderStringFormat}" 
           ContentSource="Header" Name="PART_Header" 
           HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" 
           SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" /> 
         </Border> 
         <ItemsPresenter Name="ItemsHost" Grid.Column="1" Grid.Row="1" 
             Grid.ColumnSpan="2" /> 
        </Grid> 
        <ControlTemplate.Triggers> 
         <Trigger Property="ItemsControl.HasItems"> 
          <Setter Property="UIElement.Visibility" 
            TargetName="Expander"> 
           <Setter.Value> 
            <x:Static Member="Visibility.Hidden" /> 
           </Setter.Value> 
          </Setter> 
          <Trigger.Value> 
           <system:Boolean>False</system:Boolean> 
          </Trigger.Value> 
         </Trigger> 
         <Trigger Property="TreeViewItem.IsSelected"> 
          <Setter Property="Panel.Background" TargetName="Bd"> 
           <Setter.Value> 
            <DynamicResource 
             ResourceKey="{x:Static SystemColors.HighlightBrushKey}" /> 
           </Setter.Value> 
          </Setter> 
          <Setter Property="TextElement.Foreground"> 
           <Setter.Value> 
            <DynamicResource 
             ResourceKey="{x:Static SystemColors.HighlightTextBrushKey}" /> 
           </Setter.Value> 
          </Setter> 
          <Trigger.Value> 
           <system:Boolean>True</system:Boolean> 
          </Trigger.Value> 
         </Trigger> 
         <MultiTrigger> 
          <MultiTrigger.Conditions> 
           <Condition Property="TreeViewItem.IsSelected"> 
            <Condition.Value> 
             <system:Boolean>True</system:Boolean> 
            </Condition.Value> 
           </Condition> 
           <Condition Property="Selector.IsSelectionActive"> 
            <Condition.Value> 
             <system:Boolean>False</system:Boolean> 
            </Condition.Value> 
           </Condition> 
          </MultiTrigger.Conditions> 
          <Setter Property="Panel.Background" TargetName="Bd"> 
           <Setter.Value> 
            <DynamicResource 
             ResourceKey="{x:Static SystemColors.ControlBrushKey}" /> 
           </Setter.Value> 
          </Setter> 
          <Setter Property="TextElement.Foreground"> 
           <Setter.Value> 
            <DynamicResource 
             ResourceKey="{x:Static SystemColors.ControlTextBrushKey}" /> 
           </Setter.Value> 
          </Setter> 
         </MultiTrigger> 
         <Trigger Property="UIElement.IsEnabled"> 
          <Setter Property="TextElement.Foreground"> 
           <Setter.Value> 
            <DynamicResource 
             ResourceKey="{x:Static SystemColors.GrayTextBrushKey}" /> 
           </Setter.Value> 
          </Setter> 
          <Trigger.Value> 
           <system:Boolean>False</system:Boolean> 
          </Trigger.Value> 
         </Trigger> 
        </ControlTemplate.Triggers> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
</TreeView.ItemContainerStyle> 
<TreeView.ItemTemplate> 
    <HierarchicalDataTemplate DataType="{x:Type models:FileData}" 
           ItemsSource="{Binding Path=Files}"> 
     <Grid> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="Auto" /> 
       <ColumnDefinition Width="*" /> 
      </Grid.ColumnDefinitions> 
      <Rectangle x:Name="Rect" Grid.Column="0" Width="15" Height="15" Margin="3" 
         Fill="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=TreeViewItem}, Path=Foreground}"> 
       <Rectangle.OpacityMask> 
        <VisualBrush Stretch="Fill"> 
         <VisualBrush.Visual> 
          <MultiBinding Converter="{StaticResource MultiToVisual}"> 
           <Binding Path="." /> 
           <Binding Mode="OneWay" 
             Source="{StaticResource appbar_folder}" /> 
           <Binding Mode="OneWay" 
             Source="{StaticResource appbar_folder_open}" /> 
           <Binding Mode="OneWay" 
             Source="{StaticResource appbar_page}" /> 
          </MultiBinding> 
          </VisualBrush.Visual> 
         </VisualBrush> 
       </Rectangle.OpacityMask> 
      </Rectangle> 
      <TextBlock Grid.Column="1" Margin="3" VerticalAlignment="Center" 
         Text="{Binding Path=FileName}" /> 
     </Grid> 
    </HierarchicalDataTemplate> 
</TreeView.ItemTemplate> 
</TreeView> 

以下TreeView和在VS2015的XAML設計崩潰寬度System.Runtime.Remoting.RemotingException。但是,如果我從ControlTemplate中刪除ItemsPresenter,則XAML設計器將再次開始工作。

無論哪種方式編譯和運行,雖然沒有ItemsPresenter我沒有得到像預期的結果樹。

我做錯了什麼?爲什麼XAML設計者會崩潰?如果我忽略它,這可能會回來咬我嗎?

回答

1

好的解決了這個

移動從TreeView.ItemTemplateHierarchicalDataTemplateTreeView.Resources解決了這個問題。

去圖