Reputation: 239
I'm definitely new to wpf, and I wonder, what could I do with the following situation (for example):
I have a xaml markup file, and somewhere in that file I declare two <Border>
elements, and each of them has nested elements:
<Border Grid.Row="1">
<StackPanel>
<TextBox Text="1st el"/>
<ComboBox ItemsSource="{Binding }">
</StackPanel>
</Border>
<Border Grid.Row="2">
<StackPanel>
<TextBox Text="2nd el"/>
<ComboBox ItemsSource="{Binding SomeVMProp}">
</StackPanel>
</Border>
Everything works fine, but this code seems to break DRY principle. So here're my questions:
PS Sorry if my question is incorrect, but I'm expecting somebody to give me an idea about dealing with situations like that.
Upvotes: 2
Views: 1992
Reputation: 181
Right-click your project, click New -> UserControl. Name it to whatever you want. Paste your XAML where you want it.
Use it in you MainWindow.xaml (or whatever your main window is called) by referencing <local:MyUserControl/>
.
Upvotes: 7
Reputation: 2826
You should develop custom control for this situation. You can have a custom control library. Take a look this msdn link
Upvotes: -1