Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# findResource()不使用DataTemplate_C#_.net_Pixelsense - Fatal编程技术网

C# findResource()不使用DataTemplate

C# findResource()不使用DataTemplate,c#,.net,pixelsense,C#,.net,Pixelsense,我通过以下方式定义了数据模板: <s:SurfaceWindow.Resources> <ImageBrush x:Key="WindowBackground" Stretch="None" Opacity="0.6" ImageSource="pack://application:,,,/Resources/WindowBackground.jpg"/> <DataTemplate x:Key="ContainerItemTemplate

我通过以下方式定义了数据模板:

<s:SurfaceWindow.Resources>
    <ImageBrush x:Key="WindowBackground" Stretch="None" Opacity="0.6" ImageSource="pack://application:,,,/Resources/WindowBackground.jpg"/>

        <DataTemplate x:Key="ContainerItemTemplate">
            <Grid>
                <Border BorderThickness="1" BorderBrush="White" Margin="3">
                    <s:SurfaceTextBox IsReadOnly="True" Width="120" Text="{Binding Path=name}" Padding="3"/>
                </Border>
                <s:SurfaceButton Content="Expand" Click="SourceFilePressed"></s:SurfaceButton>
            </Grid>
        </DataTemplate>

    </s:SurfaceWindow.Resources>
不幸的是,我总是在以下行中遇到NullReferenceException:

container.BarView.ItemTemplate = tmpl;
其他信息:


对象surfaceWindow在此方法中传递。它是对我在其中定义DataTemplate的文件的引用。

除非您的LibraryContainer对象的构造函数构建了LibraryContainer.BarView对象,否则此时它将为null

编辑 好的,忽略前面的尝试…我现在已经对曲面控件做了更多的阅读

返回到通过键获取数据模板的原始方法:

DataTemplate tmpl = element.FindResource("ContainerItemTemplate") 

如果在此处设置断点,那么模板是返回的还是此时为空?

谢谢。因此,我添加了container.BarView=newbarview()行;现在它开始工作了!。你的侧结是什么意思?我不太了解数据类型属性。基本上,数据模板将使用数据类型应用,因此您不需要绑定模板类型。如果我更改此项并在此处删除绑定:则不应用模板:/
container.BarView.ItemTemplate = tmpl;
DataTemplate tmpl = element.FindResource("ContainerItemTemplate")