Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8815895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:29:23+00:00 2026-06-14T04:29:23+00:00

I’m trying to create a WPF window that has a single control and 2

  • 0

I’m trying to create a WPF window that has a single control and 2 buttons displayed.
The control can be either a TextBox, ComboBox or Slider dependent on the type of object selected to launch this window.

Is it possible to do this or will I have to create a window with 3 conrtols and manipulate their position at runtime?

Regards

Tony

additions to original question

My implementation is as follows

<Window.Resources>
        <Style TargetType="TextBox" x:Key="TextBoxTemplate">
            <Setter Value="{Binding ElementName=MyWindow, Path=m_csValue}" />
        </Style>
        <Style TargetType="{x:Type ComboBox}" x:Key="ComboBoxTemplate">
            <Setter Value="{Binding ElementName=MyWindow, Path=ItemsForSelection}" />
        </Style>
        <Style TargetType="{x:Type Slider}" x:Key="SliderTemplate">
            <Setter Value="{Binding ElementName=MyWindow, Path=SliderDetail}" />
        </Style>

        <Style TargetType="{x:Type ContentControl}" x:Key="DisplayValues">
            <!-- Default Template -->
            <Setter Property="ContentTemplate" Value="{StaticResource TextBoxTemplate}" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=MyWindow, Path=eType}" Value="{x:Static local:eTagDisplay.Text}">
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <ControlTemplate Template="{StaticResource TextBoxTemplate}" />
                        </Setter.Value>
                    </Setter> 
                 </DataTrigger>
                <!-- DataTrigger Binding="{Binding ElementName=MyWindow, Path=eType}" Value="{x:Static local:eTagDisplay.Combo}">
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <ControlTemplate Template="{StaticResource ComboBoxTemplate}" />
                        </Setter.Value>
                    </Setter>
                </DataTrigger>
                <DataTrigger Binding="{Binding ElementName=MyWindow, Path=eType}" Value="{x:Static local:eTagDisplay.Slider}">
                <Setter Property="ContentTemplate">
                    <Setter.Value>
                        <ControlTemplate Template="{StaticResource SliderTemplate}" />
                    </Setter.Value>
                </Setter>
                </DataTrigger -->
            </Style.Triggers>
        </Style>
</Window.Resources>

<Grid Width="267">
    <StackPanel Name="TagEditor1">
        <!-- Text="{Binding ElementName=MyWindow, Path=m_csValue}" / -->
        <ContentControl Style="{StaticResource DisplayValues}" />
    </StackPanel>


    <Button Content="OK" Height="23" HorizontalAlignment="Left" Margin="12,154,0,0" Name="btnOK" VerticalAlignment="Top" Width="75" Click="OnClkOK" />
    <Button Content="Cancel" Height="23" HorizontalAlignment="Left" Margin="180,154,0,0" Name="btnCancel" VerticalAlignment="Top" Width="75" Click="OnClkCancel" IsCancel="True" />
</Grid>

I’m getting an error ‘System.Windows.Style’ is not a valid value for the ‘System.Windows.Controls.ContentControl.ContentTemplate’ property on a setter. I don’t know why this is happening.
My Binding is OK, i believe, as it picks up string OK….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:29:24+00:00Added an answer on June 14, 2026 at 4:29 am

    I would do this with a <ContentControl> that has a different <ContentTemplate> depending on what type of control is needed.

    You didn’t specify how the control type is being passed to the window, so your DataTrigger bindings would probably look a bit different from mine, but this should give you the right idea:

    <DataTemplate TargetType="{x:Type ContentControl}" x:Key="TextBoxTemplate">
        <TextBox ... />
    </DataTemplate>
    <DataTemplate TargetType="{x:Type ContentControl}" x:Key="ComboBoxTemplate">
        <ComboBox ... />
    </DataTemplate>
    <DataTemplate TargetType="{x:Type ContentControl}" x:Key="SliderTemplate">
        <Slider ... />
    </DataTemplate>
    
    <Style x:Key="MyStyle" TargetType="{x:Type ContentControl}">
        <!-- Default Template -->
        <Setter Property="ContentTemplate" 
                Value="{StaticResource TextBoxTemplate}" />
    
        <Style.Triggers>
            <DataTrigger Binding="{Binding SomeBoundValue}" Value="ComboBox">
                <Setter Property="ContentTemplate" 
                        Value="{StaticResource ComboBoxTemplate}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding SomeBoundValue}" Value="Slider">
                <Setter Property="ContentTemplate"
                        Value="{StaticResource SliderTemplate}" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
    
    ...
    
    <ContentControl Style="{StaticResource MyStyle}" />
    

    You could also allow users to specify a Content for your UserControl or Window, and simply display it using a ContentPresenter bound to the Content. Something like this:

    <UserControl.Template>
        <StackPanel>
            <ContentPresenter Content="{TemplateBinding Content}" />
            <Button ... />
            <Button ... />
        </StackPanel>
    </UserControl.Template>
    

    then you could use it like this:

    <local:MyUserControl>
        <TextBox ... />
    </local:MyUserControl>
    
    <local:MyUserControl>
        <ComboBox ... />
    </local:MyUserControl>
    
    <local:MyUserControl>
        <Slider ... />
    </local:MyUserControl>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.