メンバーの静的リストを使用して次のクラスを作成しました。
public class Role
{
public static List<Role> AllRoles = new List<Role>()
{
Administrators,
PowerUsers,
Limited
};
public static Role Administrators = new Role() { Name = "Bob" };
public static Role PowerUsers = new Role() { Name = "Jimbo" };
public static Role Limited = new Role() { Name = "Jack" };
public string Name { get; set; }
}
今、私はそれぞれのプロパティに基づいたアイテムテンプレートを使用してリストボックスでそれにバインドしようとしています。バインディングを機能させることができません。値が返されません。
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFTests">
<Grid>
<ListBox Width="200" Height="200"
ItemsSource="{Binding Source={x:Static local:Role.AllRoles}}">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Path=Name}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Window>
簡単なものが欠けているに違いありません。3つのメンバーの配列を表す3つのチェックボックスを取得していますが、パブリックプロパティにバインドするための結果が得られません。