简体   繁体   English

WPF:显示模板对象

[英]WPF: Displaying templated objects

This seems basic, but I want to display a representation of some CLR objects that currently exist in a DataContext. 这似乎很基本,但是我想显示DataContext中当前存在的一些CLR对象的表示形式。

I've already set up DataTemplates for how I want them to look, I just want to plop them into the visual space. 我已经设置了DataTemplates来实现它们的外观,我只想将它们放到可视空间中。

I tried this, but it doesn't help: 我试过了,但这没有帮助:

            <StackPanel>
                <Binding Path="CalibrationA" />
                <Binding Path="CalibrationB" />
            </StackPanel>

The template, for reference (its for a sensor calibration): 供参考的模板(用于传感器校准):

                <DataTemplate DataType="{x:Type ns:CalibrationTable}">
                    <StackPanel>
                        <TextBlock Text="{Binding TableName}" />
                        <ListBox ItemsSource="{Binding}" />
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding KeyName}" />
                            <TextBox Width="50"></TextBox>
                            <TextBlock Text="{Binding ValueName}" />
                            <TextBox Width="50"></TextBox>
                            <Button Content="Add" />
                        </StackPanel>
                    </StackPanel>
                </DataTemplate>

Any suggestions? 有什么建议么?

The class you're looking for is ContentPresenter: 您要查找的类是ContentPresenter:

<StackPanel>
    <ContentPresenter Content={Binding Foobar1} />
    <ContentPresenter Content={Binding Foobar1} />
<StackPanel>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM