Window
アイコンに問題があります。WPF - カスタムスタイル内にウィンドウアイコンを定義する
プロジェクト内の.xamlファイルに含まれているWindows
に対して自分自身のStyle
を作成しました。私がしたいのはWindow
の左隅にシステムIcon
を表示することです。通常、Window
に直接作業して、Icon
プロパティでIcon
を指定することができます。しかし、Window
はアイコンが定義されていないStyle
を使用しているので機能しません。 (私はプログラムを実行すると、私は例外を取得)
<Style x:Key="KavoWindowStyle" TargetType="{x:Type Window}">
<Setter Property="WindowChrome.WindowChrome">
<Setter.Value>
<WindowChrome CaptionHeight="30"
GlassFrameThickness="0"
CornerRadius="0"
NonClientFrameEdges="None"
ResizeBorderThickness="5"
UseAeroCaptionButtons="False"/>
</Setter.Value>
</Setter>
<Setter Property="Icon" Value="MyIcon.ico"/> <==================
<Setter Property="BorderBrush" Value="#2ECC71"/>
<Setter Property="Background" Value="#646464"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Grid>
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="1">
<AdornerDecorator>
<ContentPresenter/>
</AdornerDecorator>
</Border>
<DockPanel Height="30"
VerticalAlignment="Top"
LastChildFill="False">
<TextBlock VerticalAlignment="Center"
DockPanel.Dock="Left"
Margin="5,0,0,0"
FontSize="14"
Foreground="#E8E8E8"
Text="{TemplateBinding Title}"
FontFamily="Open Sans Regular"/>
</DockPanel>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
しかし、それは働いていない。だから私は自分のスタイル内部Icon
プロパティのSetter
を追加しようとしました。私はこれが正しい方法であるかどうか分かりませんが、そうでない場合は、正しいアプローチが何であるかを知りたいと思います。前もって感謝します!
アイコンをプロパティのリソースとしてマークしましたか? – Mohit
@モートあなたが.icoのファイルプロパティについて話しているなら、それは「ビルドアクション」のリソースとしてマークされています。 – Belfed