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

  • Home
  • SEARCH
  • 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 595811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:06:12+00:00 2026-05-13T16:06:12+00:00

I have the following datatemplates: First One: <DataTemplate DataType={x:Type WIAssistant:DestinationField}> <ContentControl Margin=5 MinWidth=60 MinHeight=70

  • 0

I have the following datatemplates:

First One:

<DataTemplate DataType="{x:Type WIAssistant:DestinationField}">
    <ContentControl Margin="5" MinWidth="60" MinHeight="70" >
        <Border BorderThickness="2" BorderBrush="Black" CornerRadius="5">
            <!--This text block seems un-needed.  But it allows the whole control to be dragged.  Without it only the border and the 
            text can be used to drag the control.-->
            <TextBlock>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <TextBlock FontWeight="Bold" TextWrapping="Wrap" HorizontalAlignment="Center" Margin="10" 
                               Text="{Binding DestField.Name}"/>
                    <TextBlock Grid.Row="1" TextWrapping="Wrap" HorizontalAlignment="Center" Margin="10" 
                               Text="{Binding DestField.FieldType}"/>
                </Grid>
            </TextBlock>
        </Border>
    </ContentControl>
</DataTemplate>

Second One:

<DataTemplate DataType="{x:Type WIAssistant:SourceField}">
    <ContentControl Margin="5" MinWidth="60" MinHeight="70" >
        <Border BorderThickness="2" BorderBrush="Black" CornerRadius="5">
            <!--This text block seems un-needed.  But it allows the whole control to be dragged.  Without it only the border and the 
            text can be used to drag the control.-->
            <TextBlock>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <TextBlock FontWeight="Bold" TextWrapping="Wrap" HorizontalAlignment="Center" Margin="10" 
                               Text="{Binding SrcField.Name}"/>
                    <TextBlock Grid.Row="1" TextWrapping="Wrap" HorizontalAlignment="Center" Margin="10" 
                               Text="{Binding SrcField.FieldType}"/>
                </Grid>
            </TextBlock>
        </Border>
    </ContentControl>
</DataTemplate>

They are 100% identical except for the stuff in the {}.

Is there a way to reduce the redundancy here? I fear I will make a change in one and forget to change the other.

  • 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-05-13T16:06:13+00:00Added an answer on May 13, 2026 at 4:06 pm

    As for your comment in the code – i think the problem can be solved by setting the Border‘s Background to Transparent.

    And to the main problem. You could probably have a style that describes the ContentControl, which will include the DataTemplate for the type of the SrcField and DestField properties. Then bind in it to Name and FieldType, and use it the main 2 DataTemplates. Something like this:

    <Style x:Key="SomeStyle" TargetType="ContentControl">
        <Setter Property="Margin" Value="5" />
        <Setter Property="MinWidth" Value="60" />
        <Setter Property="MinHeight" Value="70" />
        <Setter Property="ContentTemplate">
            <Setter.Value>
                <DataTemplate DataType=...> <!-- type of the `SrcField` and `DestField` properties -->
                    <Border Background="Transparent" BorderThickness="2" BorderBrush="Black" CornerRadius="5">
                         <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <TextBlock FontWeight="Bold" TextWrapping="Wrap" HorizontalAlignment="Center" Margin="10" 
                                Text="{Binding Name}"/>
                            <TextBlock Grid.Row="1" TextWrapping="Wrap" HorizontalAlignment="Center" Margin="10" 
                                Text="{Binding FieldType}"/>
                        </Grid>
                    </Border>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    
    
    <DataTemplate DataType="{x:Type WIAssistant:DestinationField}">
        <ContentControl 
            Style="{StaticResource SomeStyle}"
            Content="{Binding DestField}"
            />
    </DataTemplate>
    
    <DataTemplate DataType="{x:Type WIAssistant:SourceField}">
        <ContentControl 
            Style="{StaticResource SomeStyle}"
            Content="{Binding SrcField}"
            />
    </DataTemplate>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code currently: <DataTemplate DataType={x:Type vm:SectionViewModel}> <ScrollViewer> <ItemsControl ItemsSource={Binding ViewModels}> </ItemsControl>
I have the following xaml code in resources: <DataTemplate DataType={x:Type s:Substance}> <StackPanel Orientation=Horizontal> <TextBlock
I have a ListBox showing items using the following DataTemplate: <DataTemplate x:Key=PersonTemplate DataType={x:Type DAL:ResultItem}
I have the following DataTemplate : <DataTemplate x:Key=ColoringLabels> <TextBlock Padding=0 Margin=0 Name=Username Text={Binding Username}
I have the following ItemTemplate: <ItemsControl ItemsSource={Binding Topics}> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Orientation=Horizontal Margin=10,0> <TextBlock
So I have the following DataTemplate for a ListBox.ItemTemplate : <DataTemplate x:Key=Tweet> <Grid> <Grid.ColumnDefinitions>
Let's say i have the following DataTemplate: <DataTemplate x:Key=ListBoxItemTemplate> <Grid HorizontalAlignment=Stretch Width=440> <Grid.ColumnDefinitions> <ColumnDefinition
I have created a listbox control with following DataTemplate <DataTemplate x:Key=lb_Itemtemplate> <DockPanel> <TextBlock Text={Binding}
I have used the following template in my project: <DataTemplate x:Key=textBoxDataTemplate> <TextBox Name=textBox ToolTip={Binding
I have an ItemsControl with the following ItemTemplate: <DataTemplate x:Key=myItemTemplate> <TextBlock Height=??? Text={Binding Path=Description}

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.