【问题标题】:Xaml Internal Error error WMC9999: Object reference not set to an instance of an objectXaml 内部错误错误 WMC9999:对象引用未设置为对象的实例
【发布时间】:2018-04-12 19:37:29
【问题描述】:

这已经出现过几次了,我整天都在 UWP 应用中苦苦挣扎。

我的具体问题是我在 DataTemplate 内的 ContentTemplate 中使用 x:Bind:

<DataTemplate x:DataType="IFactionMember">
  <Button Command="{x:Bind **Property of IFactionMember**}"> // Good
    <Button.Template>
      <ControlTemplate TargetType="Button">
        <Grid Padding="10,0">
          <TextBlock Text="{x:Bind **Property of IFactionMember**}" /> // Bad
        </Grid>
      </ControlTemplate>
    </Button.Template>
  </Button>
</DataTemplate>

你不能这样做:(

【问题讨论】:

    标签: xaml uwp winrt-xaml


    【解决方案1】:

    您可以使用{Binding} 代替您的场景,例如:

    <ListView x:Name="listview" ItemsSource="{x:Bind members}">
        <ListView.ItemTemplate>
            <DataTemplate x:DataType="local:IFactionMember">
                <Button > 
                    <Button.Template>
                        <ControlTemplate TargetType="Button" >
                            <Grid Padding="10,0">
                                <TextBlock Text="{Binding  testtext}" />  
                            </Grid>
                        </ControlTemplate>
                    </Button.Template>
                </Button>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
    

    x:bind缺少{Binding}的一些特性,在x:Bind中,Path默认植根于Page,而不是DataContext,好像你这里用的是x:bind,它将尝试在MainPage 处查找该属性,从而找不到正确的属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-09
      • 2012-08-31
      • 2011-11-21
      • 2012-10-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多