Vij*_*vda 2 c# wpf xaml custom-controls material-design
我有以下自定义控件继承自TextBox:
class MyTextBox : TextBox {
//custom properties, events and functions
}
Run Code Online (Sandbox Code Playgroud)
它像这样使用..
<TextBox Width="100" Height="30" Text="TextBox" Margin="20" />
<local:MyTextBox Width="100" Height="30" Text="12345" Margin="20" />
Run Code Online (Sandbox Code Playgroud)
我在我的项目中使用了材料设计XAML工具包,这是很好用的,除了MyTextBox没有它的"Material Effect",如下面的截图所示.
如何在MyTextBox中提供该材质设计风格?
客房采用风格设计TargetType.当创建一个新类型,它没有得到拿起作为一个TextBox有MaterialDesignTextBox应用到它的风格.
您必须拥有一个样式,可能由VisualStudio在您的Generic.xaml中为MyTextBox自动创建.您需要将其更改为:
<Style TargetType="{x:Type controls:MyTextBox}" BasedOn="{StaticResource MaterialDesignTextBox}"/>
Run Code Online (Sandbox Code Playgroud)
所以WPF知道将样式应用于MyTextBox类型以及TextBox
| 归档时间: |
|
| 查看次数: |
2068 次 |
| 最近记录: |