Is it possible to define a UserControl within a ResourceDictionary, and then add it to a component within the same XAML file? Something like:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
etc.>
<Window.Resources>
<ResourceDictionary>
<UserControl x:Key="MyCustomLabel">
<Label Content="Foo"/>
...lots more here
</UserControl>
</ResourceDictionary>
</Window.Resources>
<Grid>
<MyCustomLabel /> //This doesn't work
<MyCustomLabel />
<MyCustomLabel />
</Grid>
</Window>
I could define it in its own file, but I really only need it as a subcomponent within this file. I'd use a Style, but I don't know of a way to style the content of each row of my Grid. Any ideas?
CustomLabel
do? How is it different from a regularLabel
? Why isStyle TargetType="Label"
not a solution? – Federico Berasategui