我正在關注將MenuItem
綁定到數據對象的示例。如何使用ItemContainerStyle設置MenuItem的圖標
<Menu Grid.Row="0" KeyboardNavigation.TabNavigation="Cycle"
ItemsSource="{Binding Path=MenuCommands}">
<Menu.ItemContainerStyle>
<Style>
<Setter Property="MenuItem.Header" Value="{Binding Path=DisplayName}"/>
<Setter Property="MenuItem.ItemsSource" Value="{Binding Path=Commands}"/>
<Setter Property="MenuItem.Command" Value="{Binding Path=Command}"/>
<Setter Property="MenuItem.Icon" Value="{Binding Path=Icon}"/>
</Style>
</Menu.ItemContainerStyle>
</Menu>
它所有的工作順順當當除了MenuItem
的圖標顯示爲字符串System.Drawing.Bitmap
。有問題的位圖由編譯資源中的數據對象返回。
internal static System.Drawing.Bitmap folder_page
{
get
{
object obj = ResourceManager.GetObject("folder_page", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
我在做什麼錯?
好問題......這是一個常見問題。 – cplotts 2010-04-21 16:44:17