简体   繁体   English

WPF:与 ContentControl 一起使用时未加载 DataTemplate 中的数据

[英]WPF: data in DataTemplate not getting loaded when used with ContentControl

I am using ContentControl with DataTemplate to load data but data not getting loaded.我正在使用 ContentControl 和 DataTemplate 来加载数据,但没有加载数据。

<DataTemplate DataType="{x:Type data:VesselInspectionSummaryViewModel}">                     
<StackPanel>                                  
<ContentControl Content="{Binding InternalInspections}" ContentTemplate="{StaticResource  InternalInspectionSummaryDataTemplate}"  ></ContentControl>
</StackPanel>....

My concern with ContentControl which is inside DataTemplate, definition of InternalInspectionSummaryDataTemplate is as mentioned below.我对 DataTemplate 内的 ContentControl 的关注,InternalInspectionSummaryDataTemplate 的定义如下所述。

<DataTemplate x:Key="InternalInspectionSummaryDataTemplate" >
        <TextBlock Text="{Binding  Value}"   Style="{StaticResource   HomeDetailsTitleFontStyle}"  />
</DataTemplate>

But somehow I am not able to to display text for TextBlock which is a "Value".但不知何故,我无法为 TextBlock 显示文本,这是一个“值”。 Can anyone please help me out to get value for field textBlock.任何人都可以帮我获取字段 textBlock 的价值。

Finall I got the issue, it was not related with the xaml but in Viewmodel.最后我得到了这个问题,它与 xaml 无关,而是在 Viewmodel 中。 Previous code was.以前的代码是。

private readonly ObservableCollection<InspectionUrgencyDetailViewModel> _externalInspections;
public ObservableCollection<InspectionUrgencyDetailViewModel> ExternalInspections { get; set; }

private readonly ObservableCollection<InspectionUrgencyDetailViewModel> _internalInspections;
public ObservableCollection<InspectionUrgencyDetailViewModel> InternalInspections { get; set; }

If you see properties does not corresponds to private variables so changed it to below.如果您看到属性不对应于私有变量,则将其更改为下面。

        private ObservableCollection<InspectionUrgencyDetailViewModel> _externalInspections;
        public ObservableCollection<InspectionUrgencyDetailViewModel> ExternalInspections
        {
            get { return _externalInspections; }
            set { Set(() => ExternalInspections, ref _externalInspections, value); }
        }

        private ObservableCollection<InspectionUrgencyDetailViewModel> _internalInspections;
        public ObservableCollection<InspectionUrgencyDetailViewModel> InternalInspections
        {
            get { return _internalInspections; }
            set { Set(() => InternalInspections, ref _internalInspections, value); }

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

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