Silverlight 3でItemContainerStyle
のデータバインドをListBox
に使用できません。WPFでは正常に動作します。これは、私の問題を示すために考案された例です。私が本当にしたいのは、IsSelected
というプロパティに束縛されていますが、私はこの例が従う方が簡単だと思います。Silverlight 3のItemContainerStyleでのデータバインディングに関する問題
私はObservableCollection<Item>
Item
のオブジェクトにバインドされているListBox
を持っています。ここでは
public class Item {
public String Name { get; }
public Brush Color { get; }
}
は、関連するSilverlightのXAMLです:
<ListBox x:Name="listBox" ItemsSource="{Binding .}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Background" Value="{Binding Color}"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
TargetType="ListBoxItem"
がある場合、同じXAMLは、WPFで使用することができますに置き換えられました。
WPFアプリケーションはリストボックスに項目を表示し、Item
オブジェクトのColor
プロパティに従って背景色を設定します。ただし、Silverlightアプリケーションは、AG_E_RUNTIME_MANAGED_UNKNOWN_ERROR
というテキストを持つXamlParseException
で失敗します。
Binding binding = new Binding("Color");
Setter setter = new Setter(ListBoxItem.BackgroundProperty, binding);
Style style = new Style(typeof(ListBoxItem));
style.Setters.Add(setter);
listBox.ItemContainerStyle = style;
私はこれを実行しようとする私のSilverlightコントロールが初期化された後、私はArgumentException
を取得:私も失敗し、代わりに、このように自分のスタイルを作成したXAMLを削除しようとしたことがあり、頑固な男であること。
私は間違っていますか? ItemContainerStyle
のプロパティをアイテムのプロパティにバインドするにはどうすればよいですか?
このバグと同じですか? http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?Feedback=356496 – Aardvark
同じように見えますが、1年以上前にSilverlightチームに転送されましたが、まだ修正されていません –
liversage - これを行うには良い方法がありましたか? –