【发布时间】:2021-10-06 12:35:19
【问题描述】:
希望有人能帮帮我。
我正在通过首先制作一个简单的自定义控件来尝试进入 WPF。结构如下所示。
相应的代码是 MainWindow.xaml
<Window x:Class="WPFCustomControl.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPFCustomControl.NewFolder1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<StackPanel Grid.Row="1">
<local:MyCustomControl x:Name = "customControl"
Content = "Click Me" Width = "70"
Margin = "10" Click = "customControl_Click"/>
<TextBlock Name = "txtBlock"
Width = "250" Height = "30"/>
</StackPanel>
Generic.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFCustomControl.NewFolder1">
<Style TargetType="{x:Type local:MyCustomControl}" BasedOn = "{StaticResource {x:Type Button}}">
<Setter Property = "Background" Value = "LightSalmon" />
<Setter Property = "Foreground" Value = "Blue"/>
</Style>
一切都按预期进行。 我的问题是,当我将 Themes 文件夹移动到应用程序编译的 NewFolder1 中但没有实现 Style 时。
提前感谢您提供有关如何解决此问题的任何建议。
【问题讨论】:
标签: wpf custom-controls