Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Binding an ImageBrush Problem

Reply
 
Old 06-10-2008   #1 (permalink)
star-italia


 
 

Binding an ImageBrush Problem

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

My System SpecsSystem Spec
Old 06-10-2008   #2 (permalink)
Henning Krause [MVP - Exchange]


 
 

Re: Binding an ImageBrush Problem

Hello,

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

Kind regards,
Henning Krause

"star-italia" <star-italia@xxxxxx> wrote in message
news:OL65a$uyIHA.552@xxxxxx
Quote:

> 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
My System SpecsSystem Spec
Old 06-10-2008   #3 (permalink)
star-italia


 
 

Re: Binding an ImageBrush Problem

Thank you, it worked perfectly!!!

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

Henning Krause [MVP - Exchange] wrote:
Quote:

> Hello,
>
> use a {TemplateBinding Background} instead of {Binding ...}
>
> Kind regards,
> Henning Krause
>
> "star-italia" <star-italia@xxxxxx> wrote in message
> news:OL65a$uyIHA.552@xxxxxx
Quote:

>> 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
>
My System SpecsSystem Spec
Old 06-10-2008   #4 (permalink)
Henning Krause [MVP - Exchange]


 
 

Re: Binding an ImageBrush Problem

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

"star-italia" <star-italia@xxxxxx> wrote in message
news:%23hg0YgvyIHA.1240@xxxxxx
Quote:

> Thank you, it worked perfectly!!!
>
> But. exactly, what is the difference between Binding and TemplateBinding?
>
> Henning Krause [MVP - Exchange] wrote:
Quote:

>> Hello,
>>
>> use a {TemplateBinding Background} instead of {Binding ...}
>>
>> Kind regards,
>> Henning Krause
>>
>> "star-italia" <star-italia@xxxxxx> wrote in message
>> news:OL65a$uyIHA.552@xxxxxx
Quote:

>>> 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
>>
My System SpecsSystem Spec
Old 06-11-2008   #5 (permalink)
Linda Liu[MSFT]


 
 

Re: Binding an ImageBrush Problem

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:
msdnmg@xxxxxx.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


My System SpecsSystem Spec
Old 06-13-2008   #6 (permalink)
Linda Liu[MSFT]


 
 

Re: Binding an ImageBrush Problem

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:
msdnmg@xxxxxx.

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

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
wpf xml twoway data binding problem? .NET General
Problem in dynamic WPF ListView binding .NET General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46