Binding an ImageBrush Problem

  • Thread starter Thread starter star-italia
  • Start date Start date
S

star-italia

My XAML is the following:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="FontSize" Value="16" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid Name="buttonBackground" Background="{Binding Path=Background}">
<TextBlock Text="{Binding Path=Content}" />
<ContentPresenter Margin="2" HorizontalAlignment="Center"
VerticalAlignment="Center" RecognizesAccessKey="True"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

This is my ButtonStyle. As you can see the grid background is bound to the
Background property of the button, but hen i set it, the background remains
empty

What's the error?

Thanks in advance for your help
 
Hello,

use a {TemplateBinding Background} instead of {Binding ...}

Kind regards,
Henning Krause
 
Thank you, it worked perfectly!!!

But. exactly, what is the difference between Binding and TemplateBinding?
 
Hello,

the relative source is different. {TemplateBinding Background} is equal to
{Binding Background, RelativeSource={RelativeSource TemplatedParent}}.

Google will certainly reveal more detailed explanations.

Kind regards,
Henning Krause
 
Thanks Henning for your help!

Hi Star-italia,

A TemplateBinding is an optimized form of a Binding for template scenarios,
analogous to a Binding constructed with {Binding
RelativeSource={RelativeSource TemplatedParent}}.

For more information on Binding and TemplateBinding, please refer to the
following MSDN documents:

"Binding Markup Extension"
http://msdn.microsoft.com/en-us/library/ms750413.aspx

"TemplateBinding Markup Extension"
http://msdn.microsoft.com/en-us/library/ms742882.aspx

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Star-italia,

I am reviewing this post in the newsgroup and would like to know the status
of this issue.

If you have any question, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top