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 8444651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:26:53+00:00 2026-06-10T09:26:53+00:00

I have 3 user controls Control 1 Control 2 Control 3 I have a

  • 0

I have 3 user controls

Control 1
Control 2
Control 3

I have a stack panel that contains an ItemsControl

<UserControl.Resources>
  <DataTemplate x:Key="Template1">  
      <my:UserControl1 Height="117"/>              
 </DataTemplate>    
 <DataTemplate x:Key="Template2">
  <my:UserControl3 Height="117"/>            
 </DataTemplate>    
 <DataTemplate x:Key="Template3">
   <my:UserControl3 Height="117"/>            
  </DataTemplate>    
</UserControl.Resources>  

<StackPanel Name="stackPanel3" Orientation="Vertical" VerticalAlignment="Bottom" Width="Auto">
  <ItemsControl ItemsSource="{Binding BlocksForMonth.Blocks}" ItemTemplate="{StaticResource Template1}">      
  </ItemsControl>
</StackPanel>

BlocksForMonths.Blocks is a list of view models. The Blocks class has a property called ClipType. If the clipType is 1, I want to use Template1. If its 2 I want to use Template 2. If its 3 I want to use Template 3

These templates contain different user controls

How can I do this through binding?

I have considered 1 template with the 3 controls, but I dont know how to bind the visibility?

In this XAML I am binding to a list not a single item

Paul

  • 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-10T09:26:55+00:00Added an answer on June 10, 2026 at 9:26 am

    I would put the 3 controls in the same template and use Visibility to display the correct one. What I would do is build an IValueConverter to convert the deciding value (your case it’s ClipType) and compare that to the ConverterParameter. If they are equal, return Visibility.Visible, otherwise return Visibility.Collapsed.

    <UserControl.Resources>
        <my:ClipTypeToVisibilityConverter x:Key="converter"/>
        <DataTemplate x:Key="Template">
            <StackPanel>  
                <my:UserControl1 Height="117" Visibility={Binding ClipType, Converter={StaticResource converter}, ConverterParameter=1} />              
                <my:UserControl2 Height="117" Visibility={Binding ClipType, Converter={StaticResource converter}, ConverterParameter=2} />            
                <my:UserControl3 Height="117" Visibility={Binding ClipType, Converter={StaticResource converter}, ConverterParameter=3} />            
            </StackPanel>
        </DataTemplate>    
    </UserControl.Resources>  
    
    <StackPanel Name="stackPanel3" Orientation="Vertical" VerticalAlignment="Bottom" Width="Auto">
          <ItemsControl ItemsSource="{Binding BlocksForMonth.Blocks}" ItemTemplate="{StaticResource Template}">      
          </ItemsControl>
    </StackPanel>
    

    This example assumes the ClipType property is on each item view model in the list being displayed.

    Here is a C# example converter.

        public class ClipTypeToVisibilityConverter: IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
                    var clipType = value.ToString();
    
                    if (clipType == (string)parameter))
                        return Visibility.Visible;
    
                    return Visibility.Collapsed;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    Sorry, everything was air-code. But I think you get the idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an User Control that host another controls like panel, chart controls. Right
I have a user control that contains multiple controls (CheckBox, Button, Label...). I want
I have a user control that contains a collection of controls to be reused
I have a Silverlight user control that contains an ItemsControl that renders a StackPanel
I have a Silverlight user control that has several canvas controls within a Stack
I have stack panel with custom controls in it. User can add or remove
I have a user control that i am using inside a DataTemplate , this
Let me explain my situation. I have made a user control that contains an
I have a user control that contains a stackpanel. I'm trying to find a
I have a WPF user control that contains a DataGrid. This DG contains several

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.