WPFを使用して、GroupBoxのヘッダーをポリモーフィッククラスの型名にバインドします。ですから、ElementというクラスとBasicElementやAdvancedElementのようなElementから派生した2つのクラスがある場合、GroupBoxのヘッダーに "BasicElement"や "AdvancedElement"と言ってもらいたいです。私はGroupBoxのために使用しているxamlです。 ItemsControlで使用されているDataTemplateの一部です。私は、Path = DerivedTypeNameOf(group)の代わりに、XAMLの何かを期待しています。ここで、groupはgroups配列の各グループです。WPFがクラスの型名へのパスをバインドする
TheDataのObjectInstanceが、いくつかのBasicGroupsとAdvancedGroupsの配列を保持するGroupSetの有効なインスタンスに設定されていることに注意してください。ここで
は、適切なコードビハインドクラスです:
public class Group
{
public string groupName;
public string df_groupName
{
get { return this.groupName; }
set { this.groupName = value; }
}
}
public class BasicGroup : Group
{
}
public class AdvancedGroup : Group
{
}
public class GroupSet
{
public Group [] groups;
public Group [] df_groups
{
get { return this.groups; }
set { this.groups = value; }
}
};
はここにXAMLです:
<UserControl.Resources>
<ResourceDictionary>
<ObjectDataProvider x:Key="TheData" />
<DataTemplate x:Key="GroupTemplate">
<GroupBox Header="{Binding Path=DerivedTypeNameOf(group)}">
<TextBox Text="This is some text"/>
</GroupBox>
</DataTemplate>
</ResourceDictionary>
</UserControl.Resources>
<ItemsControl ItemsSource="{Binding Source={StaticResource TheData}, Path=groups}" ItemTemplate="{StaticResource GroupTemplate}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
あなたの質問は何ですか? – miguel