我有一个ItemsControl
有其ItemsSource
组与Binding
在我ViewModel
的ObservableCollection
。我在其ItemTemplate
中使用Button
控件来显示我的数据,我在Button
内使用DataTemplate
,并且没有显示任何Binding
数据。下面是有问题的XAML:正在填充Button
DataTemplate
内XAML嵌套的DataTemplate数据绑定
<ItemsControl ItemsSource="{Binding Path=ConnectedInstruments}" HorizontalAlignment="Left">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Height="60" VerticalAlignment="Top">
<Button.ContentTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=ModelCode}" />
<TextBlock Text="{Binding Path=SerialNumber}" />
</StackPanel>
</DataTemplate>
</Button.ContentTemplate>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
无论TextBlock
控制。我知道这与Binding
路径有关,但是我对于我做错了什么感到不知所措。有人能让我走上正轨吗?
编辑
public class Instrument
{
public string ModelCode { get; set; }
public string SerialNumber { get; set; }
}
public class ViewModel
{
public ObservableCollection<Instrument> ConnectedInstruments { get; set; }
}
我知道ItemsControl
是Binding
正确与ObservableCollection
为正在显示的Button
控制正确的计数,仅模板数据丢失。
你还可以显示你的数据结构吗?视图模型 –
@VidasVasiliauskas - 我已经添加了代码 – Unflux
您是否在绑定应用后的运行时间中设置了这些值?您也不需要路径属性只需写入Text =“{Binding ModelCode}” –