2013-06-13 56 views
3

最近,我開始從擴展WPF工具包前綴「xcdg」未映射到一個命名空間

與DataGridControl打
<Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource SampleDataSource}}"> 
    <xcdg:DataGridControl ItemsSource="{Binding Orders}" SelectionMode="Single" > 
     <xcdg:DataGridControl.View> 
      <xcdg:TableflowView FixedColumnCount="1" UseDefaultHeadersFooters="True" ShowRowSelectorPane="False" VerticalGridLineBrush="Green" VerticalGridLineThickness="2" HorizontalGridLineBrush="Purple" HorizontalGridLineThickness="2"> 
       <xcdg:TableflowView.Theme> 
        <xcdg:ZuneNormalColorTheme/> 
       </xcdg:TableflowView.Theme> 
      </xcdg:TableflowView> 
     </xcdg:DataGridControl.View> 
     <xcdg:DataGridControl.Columns> 
      <xcdg:Column FieldName="OrderID" IsMainColumn="True"/> 
      <xcdg:Column FieldName="ExternalID" /> 
      <xcdg:Column FieldName="CustomerName" /> 
      <xcdg:Column FieldName="Date" /> 
      <xcdg:Column FieldName="Address" /> 
      <xcdg:Column FieldName="Items" Width="*" /> 
     </xcdg:DataGridControl.Columns> 
    </xcdg:DataGridControl> 
</Grid> 

它的確定,一切工作。然後我添加了風格。

<Style TargetType="{x:Type xcdg:DataGridControl}"> 
    <Setter Property="Background" Value="MediumOrchid"/> 
</Style> 

Style應用,一切再次工作。所以我接下來做的是使用Expression Blend創建CotrolTemplate,並將該模板添加到我的Style中。

<Style TargetType="{x:Type xcdg:DataGridControl}"> 
    <Setter Property="Background" 
      Value="MediumOrchid" /> 
    <Setter Property="Template"> 
    <Setter.Value> 
     <ControlTemplate TargetType="{x:Type xcdg:DataGridControl}"> 
     <Grid> 
      <Border BorderBrush="{TemplateBinding BorderBrush}" 
        BorderThickness="{TemplateBinding BorderThickness}" 
        Background="{TemplateBinding Background}"> 
      <AdornerDecorator x:Name="PART_DragDropAdornerDecorator"> 
       <xcdg:TableViewScrollViewer x:Name="PART_ScrollViewer" 
              Padding="{TemplateBinding Padding}" 
              RowSelectorPaneWidth="{Binding (xcdg:DataGridControl.DataGridContext).RowSelectorPaneWidth, RelativeSource={RelativeSource Self}}" 
              ShowRowSelectorPane="{Binding (xcdg:DataGridControl.DataGridContext).ShowRowSelectorPane, RelativeSource={RelativeSource Self}}"> 
       <xcdg:TableflowViewItemsHost /> 
       </xcdg:TableViewScrollViewer> 
      </AdornerDecorator> 
      </Border> 
      <Grid x:Name="connectionStateGrid" 
       HorizontalAlignment="Right" 
       Height="30" 
       Margin="0,0,25,25" 
       VerticalAlignment="Bottom" 
       Width="30"> 
      <ContentPresenter x:Name="connectionStateLoadingContentPresenter" 
           ContentTemplate="{Binding (xcdg:DataGridControl.DataGridContext).ConnectionStateLoadingGlyph, RelativeSource={RelativeSource Self}}" 
           Content="{TemplateBinding ConnectionState}" 
           Visibility="Collapsed" /> 
      <ContentPresenter x:Name="connectionStateCommittingContentPresenter" 
           ContentTemplate="{Binding (xcdg:DataGridControl.DataGridContext).ConnectionStateCommittingGlyph, RelativeSource={RelativeSource Self}}" 
           Content="{TemplateBinding ConnectionState}" 
           Visibility="Collapsed" /> 
      <ContentPresenter x:Name="connectionStateErrorContentPresenter" 
           ContentTemplate="{Binding (xcdg:DataGridControl.DataGridContext).ConnectionStateErrorGlyph, RelativeSource={RelativeSource Self}}" 
           Content="{TemplateBinding ConnectionState}" 
           Visibility="Collapsed" /> 
      </Grid> 
     </Grid> 
     <ControlTemplate.Triggers> 
      <DataTrigger Binding="{Binding (xcdg:DataGridControl.DataGridContext).IsConnectionStateGlyphEnabled, RelativeSource={RelativeSource Self}}" 
         Value="False"> 
      <Setter Property="Visibility" 
        TargetName="connectionStateGrid" 
        Value="Collapsed" /> 
      </DataTrigger> 
      <DataTrigger Binding="{Binding (xcdg:DataGridControl.DataGridContext).DataGridControl.ConnectionState, RelativeSource={RelativeSource Self}}" 
         Value="Loading"> 
      <Setter Property="Visibility" 
        TargetName="connectionStateLoadingContentPresenter" 
        Value="Visible" /> 
      <Setter Property="Visibility" 
        TargetName="connectionStateErrorContentPresenter" 
        Value="Collapsed" /> 
      <Setter Property="Visibility" 
        TargetName="connectionStateCommittingContentPresenter" 
        Value="Collapsed" /> 
      </DataTrigger> 
      <DataTrigger Binding="{Binding (xcdg:DataGridControl.DataGridContext).DataGridControl.ConnectionState, RelativeSource={RelativeSource Self}}" 
         Value="Committing"> 
      <Setter Property="Visibility" 
        TargetName="connectionStateLoadingContentPresenter" 
        Value="Collapsed" /> 
      <Setter Property="Visibility" 
        TargetName="connectionStateErrorContentPresenter" 
        Value="Collapsed" /> 
      <Setter Property="Visibility" 
        TargetName="connectionStateCommittingContentPresenter" 
        Value="Visible" /> 
      </DataTrigger> 
      <DataTrigger Binding="{Binding (xcdg:DataGridControl.DataGridContext).DataGridControl.ConnectionState, RelativeSource={RelativeSource Self}}" 
         Value="Error"> 
      <Setter Property="Visibility" 
        TargetName="connectionStateLoadingContentPresenter" 
        Value="Collapsed" /> 
      <Setter Property="Visibility" 
        TargetName="connectionStateErrorContentPresenter" 
        Value="Visible" /> 
      <Setter Property="Visibility" 
        TargetName="connectionStateCommittingContentPresenter" 
        Value="Collapsed" /> 
      </DataTrigger> 
     </ControlTemplate.Triggers> 
     </ControlTemplate> 
    </Setter.Value> 
    </Setter> 
</Style> 

但現在整個ControlTemplate被強調,並說

前綴 'xcdg' 未映射到一個命名空間。

xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid" 

無論是在我的資源字典和窗口。此外,xaml設計器在放置'DataGridControl'的'MainWindow.xaml'中拋出異常。這是

的ArgumentException: '{} DependencyProperty.UnsetValue' 不是一個二傳手的 'System.Windows.Controls.Control.Template' 屬性的有效值。

在運行時它工作正常。所有發生在我添加ControlTemplate到的DataGridControl之後。任何解釋爲什麼會發生這種情況或如何避免這種情況將受到高度讚賞。

回答

1

那麼它與VS2012 XAML設計只是問題的,這是reported和固定VS更新3

+1

VS2015更新3的解決方案還沒有固定的問題,對我來說。 @itsho提供的解決方法仍然需要。 – Gui

6

好像這個問題仍然存在VS2017。當使用綁定到名稱空間的依賴項屬性時引發異常。

我發現的解決方案是明確地將Path =添加到綁定中。

原始代碼:

<DataTrigger Binding="{Binding (xcdg:DataGridControl.DataGridContext).IsConnectionStateGlyphEnabled, RelativeSource={RelativeSource Self}}" Value="False"> 

修改後的代碼:

<DataTrigger Binding="{Binding Path=(xcdg:DataGridControl.DataGridContext).IsConnectionStateGlyphEnabled, RelativeSource={RelativeSource Self}}" Value="False"> 

我發現在Heinrich Ulbricht Blog