DataTemplate for Custom Control with ContentPresenter

W

Wonko the Sane

Hello,

I am using a custom control (based on Button), which has in its generic
implementation:

<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:BasedOnButton">
|
|
<ContentPresenter .... />
</ControlTemplate>
</Setter.Value>
</Setter Property="Template">

Now, when using this control, I have run into a situation where I want to
use a DataTrigger (to start an animation when a bound value reaches a certain
level). However, I cannot get a DataTemplate to show the data I need in that
control. I'd like something like the following:

<cust:BasedOnButton>
<cust:BasedOnButton.ContentTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=SomePath}">
<TextBlock.Triggers>
<DataTrigger
Binding="{Binding
RelativeSource={RelativeSource Seld}, Path=AnotherPath}"
Value="true">
|
|
</DataTrigger>
</TextBlock.Triggers>
</TextBlock>
</DataTemplate>
</cust:BasedOnButton.ContentTemplate>
</cust:BasedOnButton>

However, when I try to use a DataTemplate, the content of the button just
shows "Windows.System.DataTemplate"(or something like that), or nothing
(blank), depending on things I've tried.

I hope I have explained this enough....

Thanks,
WtS
 
L

Linda Liu[MSFT]

Hi Wonko,

Based on my understanding, you create a custom control based on Button and
data bind this control to a data source. The problem is that when running,
the context displayed on the custom control is
"Windows.System.DataTemplate" or an empty string, which is not what you
want. If I'm off base, please feel free to let me know.

Firstly, the code snippet you provided seems correct. Since you haven't
post the complete code of your application, it's hard for me to reproduce
the problem on my side.

Could you please create a simple application what could just reproduce the
problem and send it to me? To get my actual email address, remove 'online'
from my displayed email address.

Thank you for your undertanding and I look forward to your reply!

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
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.
 
L

Linda Liu

Hi Wonko,

I want to notify you that there's something wrong with my user account so
that I couldn't receive any email sent to my company email box these two
days.

If you have sent me a sample project that could demonstrate your problem to
my company email box, please send it to my another email address
(e-mail address removed) again.

Thank you and I look forward to your reply!

Sincerely,
Linda Liu
Microsoft Online Community Support
 
L

Linda Liu

Hi Wonko,

Thank you for your reply and sample project!

I have run the sample application on my machine and did see the problem on
my side.

After doing some research, I found the reason of this problem, i.e you
didn't specify the ContentTemplate property in the style for the
TitledButton.

In detail, open the TitledButton.Generic.xaml file and add a line of code in
it as follows:

<Style TargetType="{x:Type local:TitledButton}">
...
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:TitledButton">
...
<!-- Content Area -->
<Border ...>
<ContentPresenter
...
<!-- Add this line of code here -->
ContentTemplate="{TemplateBinding ContentTemplate}"
/>
...

Please try my suggestion to see if the problem is solved and let me know the
result.

Sincerely,
Linda Liu
Microsoft Online Community Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top