[英]Wpf Custom Popup control and application theming: Resources not found
我有一个应用程序,可以在主窗口上设置主题( ResourceDictionary
)。 然后,所有子级都通过DynamicResourceExtension
“继承”样式,主题等。 这可行。
但是,我有一个自定义的Popup控件来处理按钮上的长按动画:
class LongPressAnimationControl : Popup
{
static LongPressAnimationControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(LongPressAnimationControl),
new FrameworkPropertyMetadata(typeof(LongPressAnimationControl)));
}
/* Various DP's, events, properties, methods ETC. */
}
在Generic.xaml
具有默认样式:
<Style TargetType="{x:Type controls:LongPressAnimationControl}">
<Setter Property="Delay" Value="00:00:00.500" />
<Setter Property="Duration" Value="00:00:01.000" />
<Setter Property="Image" Value="{StaticResource Image.LongPress}" />
<Setter Property="EasingFunction"><Setter.Value><CubicEase/></Setter.Value></Setter>
</Style>
这可行。 属性将更改为样式中设置的属性。
但是,我希望弹出窗口使用Theme.xaml
定义的样式,以便可以将属性等设置为主题。
如果我将样式移到Theme.xaml
,则样式不会被拾取(属性不会更改)。 我还尝试向样式添加键,并在代码中添加资源引用,如下所示:
public LongPressAnimationControl()
{
SetResourceReference(StyleProperty, "LongPressAnimationControlStyle");
//....
}
任何人都知道如何解决这个问题?
您应该在App.xaml资源中包含Theme.xaml,以便WPF可以找到该资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.