Consider the follow 2 XAML snippets (which are side-by-side in the file):
<Button
x:Name="BuyButton"
Margin="0,0,1,1"
IsEnabled="{Binding CanBuy}"
>
<StackPanel
DataContext="{Binding Product}">
<TextBlock
Foreground="Red"
Text="BUY" />
<TextBlock
Foreground="Red"
Text="{Binding BuyPrice}" />
</StackPanel>
</Button>
<Button
x:Name="SellButton"
Margin="0,0,1,1"
IsEnabled="{Binding CanSell}"
>
<StackPanel
DataContext="{Binding Product}">
<TextBlock
Foreground="Red"
Text="SELL" />
<TextBlock
Foreground="Red"
Text="{Binding SellPrice}" />
</StackPanel>
</Button>
How does one remove duplication in WPF? I have approx 4 uses (2 shown here) of this type of button, and they're 80% the same, if not more. I could extract this into a user control and put a few DPs on it and then I'd have one control, but I fear that I will start littering my code base with tons of user controls (I have a lot of "one-off" situations like this). I don't like the DataTemplate solution here because I'd still need two templates, which would have repeated code. Without creating a bunch of templates/controls, is there a way of making this code follow DRY?