开发者

A strange problem with WPF Window.Icon

开发者 https://www.devze.com 2023-01-27 11:14 出处:网络
I\'m going to set Window.Icon property by using ResourceDictionary like below: <Style TargetType=\"{x:Type Window}\">

I'm going to set Window.Icon property by using ResourceDictionary like below:

<Style TargetType="{x:Type Window}">
    <Setter Property="Icon" Value="/WpfApplication1;component/Resources/Icon.ico" />
</Style>

Above Style wasn't change Icon of Window. However when i set Icon of Window directly, It is done correctly!

<Window Icon="/WpfApplication1;component/Resources/Icon.ico">
    //Content
</Window>

Note: Build Action of Icon.ico was set to Resource and ResourceDictionar开发者_Go百科y also loaded.


The problem is that your style is not applied at all. You'll have to define your style in app.xaml, assign a key to it and set your windows style explicitly.
EDIT:
Goblin suggested another valuable solution, excerpt from his comment:
he could set the TargetType="{local:MainWindow}" where local is the namespace for WPFApplication1. The problem is that 'empty key'-application works only for the specified type - not descendants.

0

精彩评论

暂无评论...
验证码 换一张
取 消