2
是否可以在ResourceDictionary中定义UserControl,然后将其添加到同一个XAML文件中的组件?喜欢的东西:在ResourceDictionary中定义UserControl?
<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>
我可以在自己的文件中定义它,但我真的只需要它作为这个文件中的一个子组件。我会使用Style,但我不知道如何设计Grid的每行内容。有任何想法吗?
你的CustomLabel做了什么?它和普通的'Label'有什么不同?为什么'Style TargetType =“Label”'不是解决方案? –