Using image resource in XAML markup?
I'm trying to add little icons to my tabs in WPF but having trouble with how to set up the binding.
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Source=prop:Resources.eye}" />
<Label VerticalAlignment="Center">Header</Label>
</StackPanel>
</TabItem.Header>
The xmlns:prop is set up for the local project's Properties, I am pulling other values from it elsewhere so I know that the namespace works. The markup开发者_运维知识库 above compiles fine BUT I don't see the eye image in the tab.
Also, is there any way to set this up into a template? I'm fairly new to XAML/WPF and each tab will have its own image...
Use this code. It will work :)
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Source={x:Static prop:Resources.eye}}" />
<Label VerticalAlignment="Center">Header</Label>
</StackPanel>
</TabItem.Header>
Guessing without sufficient detail in your question, but you're setting the source of the binding to the string
"prop:Resources.eye". What you want to do is resolve the string
into the resource and assign that as the source:
<Image Source="{Binding Source={StaticResource prop:Resources.eye}}" />
精彩评论