저는 WPF가 새로 도입되었습니다. 아래는 버튼에 동일한 controlTemplate
을 사용하기 위해 시도한 것입니다.이 두 버튼의 유일한 차이는 PathGeometry
입니다. 나는 응용 프로그램을 실행하려고하면 디자이너 실제로 내가 원하는 것을 정확하게 얻을 수 있지만에서 비슷한 단추에 같은 템플릿을 사용하는 방법
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Shared.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style TargetType="Button" x:Key="buttonHeader">
<Setter Property="Width" Value="18" />
<Setter Property="Height" Value="18" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="BorderStyle" Background="Transparent" >
<Path
x:Name="CheckMark"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
SnapsToDevicePixels="False"
Stroke="#FF4D4D4D"
StrokeThickness="2" StrokeEndLineCap="Flat" StrokeStartLineCap="Flat"
Data="{DynamicResource geoPath}">
</Path>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="BorderStyle" Property="Background" Value="#B2FFFFFF" />
<Setter TargetName="CheckMark" Property="Stroke" Value="#D8727272" />
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="BorderStyle" Property="Background" Value="#B2707070" />
<Setter TargetName="CheckMark" Property="Stroke" Value="#D8FFFFFF" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<PathGeometry x:Key="X_Sign">
<PathFigure StartPoint="0,0">
<LineSegment Point="10,10"/>
</PathFigure>
<PathFigure StartPoint="0,10">
<LineSegment Point="10,0"/>
</PathFigure>
</PathGeometry>
<PathGeometry x:Key="Min_Sign">
<PathFigure StartPoint="0,0">
<LineSegment Point="10,0"/>
</PathFigure>
</PathGeometry>
<Style x:Key="ButtonX" BasedOn="{StaticResource buttonHeader}" TargetType="Button">
<Style.Resources>
<StaticResource x:Key="geoPath" ResourceKey="X_Sign"/>
</Style.Resources>
</Style>
<Style x:Key="ButtonXMinimize" BasedOn="{StaticResource buttonHeader}" TargetType="Button">
<Style.Resources>
<StaticResource x:Key="geoPath" ResourceKey="Min_Sign"/>
</Style.Resources>
</Style>
</ResourceDictionary>
내가는
XamlParseException
얻을과의 InnerException은 다음과 같습니다
유형의 개체를 캐스팅 할 수 없습니다 '시스템. Windows.Media.PathGeometry '를 입력하여'System.Windows.ResourceDictionary '
누락 된 부분과 해결 방법은 무엇입니까? 또한 더 좋은 방법이 있는지 알고 행복하겠습니다.
미리 감사드립니다.
네, 그것은 같은 작품을 이렇게하면 자원으로
PathFigureCollection
자체를 저장할 수 있음을 의미 지금 매력. 고맙습니다. –