wpf - 前缀 'xcdg' 未映射到命名空间

标签 wpf xaml controltemplate xceed-datagrid

我最近开始使用 Extended WPF Toolkit 中的 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被应用,一切都再次正常。所以我接下来要做的是创建 CotrolTemplate使用 Expression Blend 并将该模板添加到我的样式中。
<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带下划线,上面写着

Prefix 'xcdg' does not map to a namespace.




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

在我的资源字典和窗口中。此外,xaml 设计器在放置“DataGridControl”的“MainWindow.xaml”中引发异常。它是

ArgumentException: '{DependencyProperty.UnsetValue}' is not a valid value for the 'System.Windows.Controls.Control.Template' property on a Setter.



在运行时它工作正常。一切发生在我添加 ControlTemplate 之后至StyleDataGridControl .任何解释为什么会发生这种情况或如何避免这种情况都将受到高度赞赏。

最佳答案

似乎这个问题在 VS2017 中仍然存在。使用命名空间绑定(bind)到依赖属性时会引发异常。

我找到的解决方案是显式添加 路径= 到绑定(bind)。

原始代码:

<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 中找到了解决方案

关于wpf - 前缀 'xcdg' 未映射到命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17086706/

相关文章:

c# - 在 C# 中,如何将刷新/重绘消息发送到 WPF 网格或 Canvas ?

c# - 让 WPF 控件触发和设置另一个控件的 itemssource

c# - 当文本框为空或来自 xaml 的空格时禁用按钮

c# - 通知列表 wpf .net4.0 中的更改

wpf - TreeView 第二层的 ControlTemplate

wpf - wpf中控制模板和数据模板的区别

c# - 与 ElementName 绑定(bind)不适用于 WPF TabItem 内的动态构造控件

wpf - 如何让 ScrollViewer 在 StackPanel 中工作?

wpf - 设计时 WPF 中的多列 ListView

c# - 在 WPF 中,是否可以在 UserControl 本身内部为 UserControl 定义 ControlTemplate(在 VS 中不会收到警告/错误)?