Wpf XMLDataProvider绑定到UserControl DependencyProperties不起作用

Wpf XMLDataProvider绑定到UserControl DependencyProperties不起作用,wpf,xaml,binding,user-controls,xmldataprovider,Wpf,Xaml,Binding,User Controls,Xmldataprovider,由于某些原因,当绑定到UserControl时,我的XMLDataProvider无法工作,否则它确实可以工作 我的用户控件,CreditExpander: using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using S

由于某些原因,当绑定到UserControl时,我的XMLDataProvider无法工作,否则它确实可以工作

我的用户控件,CreditExpander:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace UI.Credits.Controls
{
    public partial class CreditExpander : UserControl
    {
        #region DEPENDENCY PROPERTIES
        public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(CreditExpander), new PropertyMetadata("Title", ABC));
        public string Title
        {
            get { return (string)GetValue(NameProperty); }
            set { SetValue(NameProperty, value); }
        }

        public static readonly DependencyProperty HomepageUrlProperty = DependencyProperty.Register("HomepageUrl", typeof(string), typeof(CreditExpander), new PropertyMetadata("http://www.google.com"));
        public string HomepageUrl
        {
            get { return (string)GetValue(HomepageUrlProperty); }
            set { SetValue(HomepageUrlProperty, value); }
        }

        public static readonly DependencyProperty LicenceProperty = DependencyProperty.Register("Licence", typeof(string), typeof(CreditExpander), new PropertyMetadata("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum"));
        public string Licence
        {
            get { return (string)GetValue(LicenceProperty); }
            set { SetValue(LicenceProperty, value); }
        }

        public static readonly DependencyProperty IsLicenceVisibleProperty = DependencyProperty.Register("IsLicenceVisible", typeof(bool), typeof(CreditExpander), new PropertyMetadata(false));
        public bool IsLicenceVisible
        {
            get { return (bool)GetValue(IsLicenceVisibleProperty); }
            set { SetValue(IsLicenceVisibleProperty, value); }
        }
        #endregion

        #region CONSTRUCTOR(S)
        public CreditExpander()
        {
            InitializeComponent();
        }
        #endregion

        #region PRIVATE METHODS
        private static void ABC(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {

        }

        private void Homepage_Click(object sender, RoutedEventArgs e)
        {
            Process.Start(new ProcessStartInfo(this.HomepageUrl));
        }

        private void ShowLicence_Click(object sender, RoutedEventArgs e)
        {
            IsLicenceVisible = !IsLicenceVisible;
        }
        #endregion
    }
}
UserControl XAML:

<UserControl x:Class="UI.Credits.Controls.CreditExpander"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="BoolVisibilityConverter" />
    </UserControl.Resources>

    <Grid  Margin="5">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <!--header-->
        <Grid Background="#C3D9FF">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="auto" />
            </Grid.ColumnDefinitions>

            <TextBlock Text="{Binding Title}" Padding="10" FontWeight="Bold" FontSize="14" />
            <TextBlock Grid.Column="1" VerticalAlignment="Center" Padding="10">
                <Hyperlink NavigateUri="{Binding HomepageUrl}" Click="Homepage_Click">Homepage</Hyperlink>
            </TextBlock>
            <TextBlock Grid.Column="2" VerticalAlignment="Center" Padding="10">
                <Hyperlink Click="ShowLicence_Click">
                    <TextBlock>
                        <TextBlock.Style>
                            <Style TargetType="TextBlock">
                                <Style.Triggers>
                                    <!--toggle text-->
                                    <DataTrigger Binding="{Binding IsLicenceVisible}" Value="True">
                                        <Setter Property="Text" Value="Hide Licence" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding IsLicenceVisible}" Value="False">
                                        <Setter Property="Text" Value="Show Licence" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>
                </Hyperlink>
            </TextBlock>
        </Grid>

        <!--licence-->
        <TextBlock Name="txtLicence" Grid.Row="1" Text="{Binding Licence}" Visibility="{Binding IsLicenceVisible, Converter={StaticResource  BoolVisibilityConverter}}" TextWrapping="Wrap" FontFamily="Consolas" FontSize="11" Padding="5" Background="#E8EEF7"/>
    </Grid>
</UserControl>

主页
完成绑定的主窗口:

<Window x:Class="UI.Credits.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ctrl="clr-namespace:UI.Credits.Controls"
        Title="Credits" Height="350" Width="525"
        DataContext="{Binding RelativeSource={RelativeSource Self}}">

    <Window.Resources>
        <XmlDataProvider x:Key="CreditsData"  Source="Data\Credits.xml" XPath="Credits" IsAsynchronous="True" />
    </Window.Resources>

    <ItemsControl ItemsSource="{Binding Source={StaticResource CreditsData}, XPath=Credit}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <!--works-->
                <StackPanel Orientation="Horizontal">
                    <TextBlock FontSize="12" Foreground="Red" Text="{Binding XPath=Title}"/>
                    <TextBlock FontSize="12" Foreground="Red" Text="{Binding XPath=HomepageUrl}"/>
                </StackPanel>

                <!--does not work-->
                <!--<ctrl:CreditExpander Title="{Binding XPath=Title}" HomepageUrl="{Binding XPath=HomepageUrl}" Licence="{Binding XPath=Licence}" />-->
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</Window>

参考资料中的我的XML文件:

<?xml version="1.0" encoding="utf-8" ?>
<Credits>
  <Credit>
    <Title>moq</Title>
    <HomepageUrl>https://github.com/Moq/moq</HomepageUrl>
    <Licence>
      Apache License
      Version 2.0, January 2004
      http://www.apache.org/licenses/

      TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

      1. Definitions.

      "License" shall mean the terms and conditions for use, reproduction, and
      distribution as defined by Sections 1 through 9 of this document.

      "Licensor" shall mean the copyright owner or entity authorized by the copyright
      owner that is granting the License.

      "Legal Entity" shall mean the union of the acting entity and all other entities
      that control, are controlled by, or are under common control with that entity.
      For the purposes of this definition, "control" means (i) the power, direct or
      indirect, to cause the direction or management of such entity, whether by
      contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
      outstanding shares, or (iii) beneficial ownership of such entity.

      "You" (or "Your") shall mean an individual or Legal Entity exercising
      permissions granted by this License.

      "Source" form shall mean the preferred form for making modifications, including
      but not limited to software source code, documentation source, and configuration
      files.

      "Object" form shall mean any form resulting from mechanical transformation or
      translation of a Source form, including but not limited to compiled object code,
      generated documentation, and conversions to other media types.

      "Work" shall mean the work of authorship, whether in Source or Object form, made
      available under the License, as indicated by a copyright notice that is included
      in or attached to the work (an example is provided in the Appendix below).

      "Derivative Works" shall mean any work, whether in Source or Object form, that
      is based on (or derived from) the Work and for which the editorial revisions,
      annotations, elaborations, or other modifications represent, as a whole, an
      original work of authorship. For the purposes of this License, Derivative Works
      shall not include works that remain separable from, or merely link (or bind by
      name) to the interfaces of, the Work and Derivative Works thereof.

      "Contribution" shall mean any work of authorship, including the original version
      of the Work and any modifications or additions to that Work or Derivative Works
      thereof, that is intentionally submitted to Licensor for inclusion in the Work
      by the copyright owner or by an individual or Legal Entity authorized to submit
      on behalf of the copyright owner. For the purposes of this definition,
      "submitted" means any form of electronic, verbal, or written communication sent
      to the Licensor or its representatives, including but not limited to
      communication on electronic mailing lists, source code control systems, and
      issue tracking systems that are managed by, or on behalf of, the Licensor for
      the purpose of discussing and improving the Work, but excluding communication
      that is conspicuously marked or otherwise designated in writing by the copyright
      owner as "Not a Contribution."

      "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
      of whom a Contribution has been received by Licensor and subsequently
      incorporated within the Work.

      2. Grant of Copyright License.

      Subject to the terms and conditions of this License, each Contributor hereby
      grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
      irrevocable copyright license to reproduce, prepare Derivative Works of,
      publicly display, publicly perform, sublicense, and distribute the Work and such
      Derivative Works in Source or Object form.

      3. Grant of Patent License.

      Subject to the terms and conditions of this License, each Contributor hereby
      grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
      irrevocable (except as stated in this section) patent license to make, have
      made, use, offer to sell, sell, import, and otherwise transfer the Work, where
      such license applies only to those patent claims licensable by such Contributor
      that are necessarily infringed by their Contribution(s) alone or by combination
      of their Contribution(s) with the Work to which such Contribution(s) was
      submitted. If You institute patent litigation against any entity (including a
      cross-claim or counterclaim in a lawsuit) alleging that the Work or a
      Contribution incorporated within the Work constitutes direct or contributory
      patent infringement, then any patent licenses granted to You under this License
      for that Work shall terminate as of the date such litigation is filed.

      4. Redistribution.

      You may reproduce and distribute copies of the Work or Derivative Works thereof
      in any medium, with or without modifications, and in Source or Object form,
      provided that You meet the following conditions:

      You must give any other recipients of the Work or Derivative Works a copy of
      this License; and
      You must cause any modified files to carry prominent notices stating that You
      changed the files; and
      You must retain, in the Source form of any Derivative Works that You distribute,
      all copyright, patent, trademark, and attribution notices from the Source form
      of the Work, excluding those notices that do not pertain to any part of the
      Derivative Works; and
      If the Work includes a "NOTICE" text file as part of its distribution, then any
      Derivative Works that You distribute must include a readable copy of the
      attribution notices contained within such NOTICE file, excluding those notices
      that do not pertain to any part of the Derivative Works, in at least one of the
      following places: within a NOTICE text file distributed as part of the
      Derivative Works; within the Source form or documentation, if provided along
      with the Derivative Works; or, within a display generated by the Derivative
      Works, if and wherever such third-party notices normally appear. The contents of
      the NOTICE file are for informational purposes only and do not modify the
      License. You may add Your own attribution notices within Derivative Works that
      You distribute, alongside or as an addendum to the NOTICE text from the Work,
      provided that such additional attribution notices cannot be construed as
      modifying the License.
      You may add Your own copyright statement to Your modifications and may provide
      additional or different license terms and conditions for use, reproduction, or
      distribution of Your modifications, or for any such Derivative Works as a whole,
      provided Your use, reproduction, and distribution of the Work otherwise complies
      with the conditions stated in this License.

      5. Submission of Contributions.

      Unless You explicitly state otherwise, any Contribution intentionally submitted
      for inclusion in the Work by You to the Licensor shall be under the terms and
      conditions of this License, without any additional terms or conditions.
      Notwithstanding the above, nothing herein shall supersede or modify the terms of
      any separate license agreement you may have executed with Licensor regarding
      such Contributions.

      6. Trademarks.

      This License does not grant permission to use the trade names, trademarks,
      service marks, or product names of the Licensor, except as required for
      reasonable and customary use in describing the origin of the Work and
      reproducing the content of the NOTICE file.

      7. Disclaimer of Warranty.

      Unless required by applicable law or agreed to in writing, Licensor provides the
      Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
      including, without limitation, any warranties or conditions of TITLE,
      NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
      solely responsible for determining the appropriateness of using or
      redistributing the Work and assume any risks associated with Your exercise of
      permissions under this License.

      8. Limitation of Liability.

      In no event and under no legal theory, whether in tort (including negligence),
      contract, or otherwise, unless required by applicable law (such as deliberate
      and grossly negligent acts) or agreed to in writing, shall any Contributor be
      liable to You for damages, including any direct, indirect, special, incidental,
      or consequential damages of any character arising as a result of this License or
      out of the use or inability to use the Work (including but not limited to
      damages for loss of goodwill, work stoppage, computer failure or malfunction, or
      any and all other commercial damages or losses), even if such Contributor has
      been advised of the possibility of such damages.

      9. Accepting Warranty or Additional Liability.

      While redistributing the Work or Derivative Works thereof, You may choose to
      offer, and charge a fee for, acceptance of support, warranty, indemnity, or
      other liability obligations and/or rights consistent with this License. However,
      in accepting such obligations, You may act only on Your own behalf and on Your
      sole responsibility, not on behalf of any other Contributor, and only if You
      agree to indemnify, defend, and hold each Contributor harmless for any liability
      incurred by, or claims asserted against, such Contributor by reason of your
      accepting any such warranty or additional liability.

      END OF TERMS AND CONDITIONS

      APPENDIX: How to apply the Apache License to your work

      To apply the Apache License to your work, attach the following boilerplate
      notice, with the fields enclosed by brackets "[]" replaced with your own
      identifying information. (Don't include the brackets!) The text should be
      enclosed in the appropriate comment syntax for the file format. We also
      recommend that a file or class name and description of purpose be included on
      the same "printed page" as the copyright notice for easier identification within
      third-party archives.

      Copyright 2013 Clarius Consulting, Daniel Cazzulino

      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    </Licence>
  </Credit>
  <Credit>
    <Title>math.net</Title>
    <HomepageUrl>http://www.mathdotnet.com</HomepageUrl>
    <Licence>
      Copyright (c) 2002-2014 Math.NET

      Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

      The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    </Licence>
  </Credit>
</Credits>

最小起订量
https://github.com/Moq/moq
Apache许可证
版本2.0,2004年1月
http://www.apache.org/licenses/
使用、复制和分发的条款和条件
1.定义。
“许可证”是指使用、复制和使用的条款和条件
本文件第1节至第9节规定的分发。
“许可方”是指版权所有人或版权委员会授权的实体
授予许可证的所有者。
“法人实体”是指代理实体和所有其他实体的联合体
该控制权,由该实体控制,或与该实体处于共同控制之下。
在本定义中,“控制”指(i)直接或间接的权力
间接的,导致该实体的指导或管理,无论是通过
合同或其他,或(ii)百分之五十(50%)或以上的所有权
已发行股份,或(iii)该实体的实益所有权。
“您”(或“您的”)系指行使下列权利的个人或法人实体:
此许可证授予的权限。
“来源”表格应指进行修改的首选表格,包括
但不限于软件源代码、文档源和配置
文件夹。
“物体”形式应指由机械变形或变形产生的任何形式
源格式的翻译,包括但不限于编译的目标代码,
生成文档,并转换为其他媒体类型。
“作品”系指作者创作的作品,无论是源作品还是目标作品
根据许可证提供,如包含的版权声明所示
在工程中或附在工程上(以下附录中提供了一个示例)。
“衍生作品”是指任何作品,无论是源作品还是目标作品
基于(或源自)作品,且编辑修订,
注释、详细说明或其他修改作为一个整体表示
原创作品。就本许可而言,衍生作品
不应包括可分离的工程,或仅通过
名称)的接口、工程及其衍生工程。
“贡献”系指任何原创作品,包括原始版本
本作品及其任何修改或增补或衍生作品
其中,故意提交给许可方以包含在作品中
由版权所有人或经授权提交
代表版权所有人。就本定义而言,
“提交”是指发送的任何形式的电子、口头或书面通信
许可方或其代表,包括但不限于
关于电子邮件列表、源代码控制系统和
由许可方或其代表管理的问题跟踪系统
讨论和改进工作的目的,但不包括沟通
版权局以书面形式显著标记或指定的
所有者被视为“非出资人”
“出资人”是指许可人和代表许可人的任何个人或法人实体
其中,许可方已收到出资,且随后
包含在作品中。
2.版权许可的授予。
根据本许可证的条款和条件,每位贡献者特此
授予您永久、全球、非独家、免费、免版税、,
不可撤销的版权许可证,用于复制、准备,
公开展示、公开执行、再授权和分发作品等
衍生作品以源或客体形式出现。
3.专利许可的授予。
根据本许可证的条款和条件,每位贡献者特此
授予您永久、全球、非独家、免费、免版税、,
不可撤销(除非本节另有规定)的专利许可
制作、使用、提议出售、出售、进口和以其他方式转让作品,如果
该许可仅适用于该贡献者可许可的专利权利要求
因其单独或组合的贡献而必然受到侵犯的
他们对工作的贡献是什么
提交。如果您对任何实体提起专利诉讼(包括
(诉讼中的交叉索赔或反索赔)声称作品