【发布时间】:2013-09-28 21:37:02
【问题描述】:
我有一个单独的解决方案,我想在其中创建一个用户控件库,我可以在其他项目中将其作为 dll 引用(所以只使用 dll,不使用 xaml+code)。
比如我可以有这样一个控件:
<UserControl x:Class="WpfUserControlsLibrary.PlayerControls"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<Style x:Key="btnPlayer" TargetType="{x:Type Button}">
<Setter Property="Width" Value="100"/>
<Setter Property="Height" Value="50"/>
</Style>
</UserControl.Resources>
<StackPanel Orientation="Horizontal">
<Button Style="{StaticResource btnPlayer}" Name="btnPlay" Click="btnPlay_Click">Play</Button>
<Button Style="{StaticResource btnPlayer}" Name="btnStop" Click="btnStop_Click">Stop</Button>
<Button Style="{StaticResource btnPlayer}" Name="btnPause" Click="btnPause_Click">Pause</Button>
</StackPanel>
</UserControl>
对于上面的代码,假设有另一个解决方案 TestUI 引用了 WpfUserControlsLibrary 的 dll,我想要以下内容:
- 使用按钮的默认样式
- 如果 TestUI 有自定义的外观和感觉,我希望能够通过定义或继承 TestUI 资源来更改按钮的默认样式(我还不知道这部分是否可以完成或如何完成)
是否有任何方法可以声明此控件或定义其样式/模板,以便可以从引用此 dll 的另一个项目自定义其 UI(同时保留代码隐藏功能)?
【问题讨论】:
标签: c# wpf templates dll styles