У меня есть следующие DataTemplates:Refactor DataTemplate (XAML), чтобы уменьшить дублирование
Первый:
<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>
Второй:
<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>
Они являются 100% идентичны, за исключением материала, за исключением в {}.
Есть ли способ уменьшить избыточность здесь? Я боюсь, что сделаю изменения в одном и забываю изменить другого.
Я хотел бы поддержать это. Можете ли вы отредактировать его, чтобы я мог. («Хромая» функция «препятствует тому, чтобы я формировал upvoting: http://meta.stackexchange.com/questions/21462/undoing-an-old-vote-cannot-be-recast-because-vote-is-too-old) – Vaccano
@vacc done thx. – Will