나는 이것을 가장 잘 수행하는 방법을 잘 모르겠습니다. 이미지를 사용하고자하는 버튼의 템플리트가 있습니다.이 템플리트의 다른 인스턴스에 따라 다릅니다. 그 버튼의 템플릿.템플릿의 콘텐츠에서 이미지 사용하기
코드 : 그것은 "달성하는 방법이"를 말합니다 곳
<Style TargetType="Button" x:Key="iconButton">
<Style.Resources>
<!-- add the "content to image source" converter-->
<converters:ContentToImageSourceConverter x:Key="ContentToImageSourceConverter"/>
</Style.Resources>
<Setter Property="Foreground" Value="{DynamicResource foreground_color}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Margin="5">
<Ellipse x:Name="circle" Width="45" Height="45" Fill="{DynamicResource foreground_color}" Opacity="0"/>
<Ellipse Width="45" Height="45" Fill="{DynamicResource foreground_color}">
<Ellipse.OpacityMask>
<!--How to accomplish this?-->
<ImageBrush ImageSource="{TemplateBinding Property=Content "/>
</Ellipse.OpacityMask>
</Ellipse>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="circle" Property="Opacity" Value="0.15"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="circle" Property="Opacity" Value="0.3"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
라인에서보세요. 나는 이미지를 소스로 사용하고하지만 난 당신이 버튼을 사용할 때마다 이미지가 예를 들어, 정의하려는 :
<Button Style="{StaticResource iconButton}" DockPanel.Dock="Right">
<Image Source="/Sources/settings_icon.png"/>
</Button>
내가하지 단순히 버튼 때문에의 내용으로 이미지를 렌더링 할 할 나는 그것을 다른 마스크로 사용하고 있기 때문에 전경색을 변경하고 아이콘을 다른 색상으로 렌더링 할 수 있습니다.
필자는 WPF에 익숙하지 않으며 그것을 달성하는 가장 좋은 방법이 무엇인지 확신하지 못한다.
안녕하세요 저는 WPF를 처음 사용하기 때문에 아직 "사용자 정의 컨트롤"을 사용하는 방법을 실제로 배웠지 만 그 점을 확인해 보겠습니다. 감사! –