전설에있는 항목에 대한 종속성 속성이 있습니다.WPF 속성 설정자에서 컬렉션 지정
public List<LegendItem> LegendItems
{
get { return (List<LegendItem>)GetValue(LegendItemsProperty); }
set { SetValue(LegendItemsProperty, value); }
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty LegendItemsProperty =
DependencyProperty.Register("LegendItems", typeof(List<LegendItem>), typeof(TipScoreboard), new PropertyMetadata());
곳 LegendItem
가 UserControl
입니다 : 것 같습니다.
XAML에서 아무 문제없이 설정할 수 있습니다.
<local:TipScoreboard.LegendItems>
<local:LegendItem ItemFillBrush="{DynamicResource GreenStatusBrush}"
Label="{x:Static res:TipLabels.GoodScan}"/>
<local:LegendItem ItemFillBrush="{DynamicResource RedStatusBrush}"
Label="{x:Static res:TipLabels.BadScan}"/>
</local:TipScoreboard.LegendItems>
그러나이 같은 세터에서이 속성을 설정 갈 때 :
<Setter Property="LegendItems">
<Setter.Value>
<local:LegendItem ItemFillBrush="{DynamicResource GreenStatusBrush}"
Label="{x:Static res:TipLabels.GoodScan}"/>
<local:LegendItem ItemFillBrush="{DynamicResource YellowStatusBrush}"
Label="{x:Static res:TipLabels.LowConfidence}"/>
</Setter.Value>
</Setter>
내가 세터의
The property "Value" is set more than once.
를 얻을. 나는 이것을 어떻게 감쌀 것인지, 무엇을 해야할지 모르겠다. 난 그냥 주위에 목록을 래핑 해봤지만 작동하지 않는 것.
EDIT : 사용자 지정 래핑 된 컬렉션을 만들려고했지만 모든 내용이 적용되고 실행되지만 내용은 비어 있습니다.
public class LegendItemCollection : Collection<LegendItem>
{
}
public LegendItemCollection LegendItems
{
get { return (LegendItemCollection)GetValue(LegendItemsProperty); }
set { SetValue(LegendItemsProperty, value); }
}
public static readonly DependencyProperty LegendItemsProperty =
DependencyProperty.Register("LegendItems", typeof(LegendItemCollection), typeof(TipScoreboard), new PropertyMetadata());
와 XAML :
public class LegendItemCollection : List<LegendItem>
{
}
public LegendItemCollection LegendItems
{
get { return (LegendItemCollection)GetValue(LegendItemsProperty); }
set { SetValue(LegendItemsProperty, value); }
}
public static readonly DependencyProperty LegendItemsProperty =
DependencyProperty.Register("LegendItems", typeof(LegendItemCollection), typeof(TipScoreboard),
new PropertyMetadata((sender, args) => {
System.Diagnostics.Debug.WriteLine("LegendItems property set");
}));
는 그런 다음 속성을 설정할 수 있습니다 :이 처리하는
<Setter Property="LegendItems">
<Setter.Value>
<local:LegendItemCollection>
<local:LegendItem ItemFillBrush="{DynamicResource GreenStatusBrush}"
Label="{x:Static res:TipLabels.GoodScan}"/>
<local:LegendItem ItemFillBrush="{DynamicResource YellowStatusBrush}"
Label="{x:Static res:TipLabels.LowConfidence}"/>
</local:LegendItemCollection>
</Setter.Value>
</Setter>
나는 사용자 지정 래퍼를 시도하고 실행했지만 작동하지 않았다. 그냥 비워 둬. List 접근 방식을 시도 할 때와 같은 오류가 발생했습니다. –
@BrianTriplett 3 곳 모두에서 DP 유형을 "LegendItemCollection"으로 업데이트하셨습니까? 그게 지금 당장 생각할 수있는 유일한 것입니다. 또한 출력 창에서 바인딩 오류를 확인할 수 있습니다 ... – McGarnagle
확인했는데 모두 올바르게 설정되었습니다. 초기화는 어떻습니까? 뷰 생성자에서 this.LegendItems = new LegendItemCollection(); InitializeComponent(); ' –