Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

DataTemplate for Custom Control with ContentPresenter

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Wonko the Sane - 03 Mar 2008 17:14 GMT
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
Linda Liu[MSFT] - 04 Mar 2008 08:30 GMT
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.
Linda Liu - 05 Mar 2008 09:22 GMT
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
liuting_lliu@hotmail.com again.

Thank you and I look forward to your reply!

Sincerely,
Linda Liu
Microsoft Online Community Support
Linda Liu - 06 Mar 2008 08:31 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.