【发布时间】:2017-02-25 10:55:28
【问题描述】:
我的代码没有绑定到可观察集合中项目的 X 和 Y 属性。怎么了:
<ItemsControl ItemsSource="{Binding LED}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas Background="SkyBlue"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="{Binding X}" />
<Setter Property="Canvas.Top" Value="{Binding Y}" />
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Ellipse Stroke="{Binding Color}" Fill="{Binding FillColor}" StrokeThickness="1" Width="40" Height="40"></Ellipse>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
它确实绑定到 Color 和 FillColor。 这是存储在 ObservableCollection LED 中的 Shape 类:
class Shape
{
public int X { get; private set; }
public int Y { get; private set; }
public string Color { get; private set; }
public string FillColor { get; private set; }
public Shape (int x, int y, string color, string fillColor)
{
X = x;
Y = y;
Color = color;
FillColor = fillColor;
}
}
【问题讨论】:
标签: c# uwp win-universal-app