मीकल, मैं एक असली "बटन" नहीं बनाता। बस मिश्रण करने के लिए जाएं, अपनी छवि को एक आयत में एक छवि ब्रश के रूप में प्राप्त करें, इसे एक बटन बनाएं पर राइट-क्लिक करें। यदि आप ब्लेंड 4 का उपयोग कर रहे हैं, तो यह विजुअल स्टेट मैनेजर में उपयुक्त राज्य उत्पन्न करेगा। बटन की तरह दिखने के लिए आप अपना माउस ओवर, दबाए, इत्यादि प्राप्त कर सकते हैं। यहां तक कि अक्षम राज्य भी।
<Button Content="This is my crazy button" Style="{DynamicResource CrazyButtonStyle}"/>
मैं जानता हूँ कि इस बटन के रूप में पारदर्शी PNG का उपयोग नहीं है, लेकिन यह करता है, तो एक बेहतर विकल्प होगा: इस प्रकार
<Window.Resources>
<Style x:Key="CrazyButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="path">
<EasingColorKeyFrame KeyTime="0" Value="#FFBEBEBE"/>
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="path">
<EasingColorKeyFrame KeyTime="0" Value="#FF919191"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="path">
<EasingColorKeyFrame KeyTime="0" Value="#FF782B2B"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="path">
<EasingColorKeyFrame KeyTime="0" Value="#FF1D0C0C"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="path">
<EasingColorKeyFrame KeyTime="0" Value="#FF720505"/>
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="path">
<EasingColorKeyFrame KeyTime="0" Value="#FF6E0000"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Path x:Name="path" Data="M95.5,33.499981 C71.500031,31.499967 76.5,68.5 76.5,68.5 L112.5,75.500276 107.5,92.500393 144.5,105.50048 152.5,79.500301 132.5,63.50019 154.5,54.500128 173.5,68.500225 168.5,87.500356 172.5,97.500425 185.5,96.500418 197.12084,75.753906 200.12084,44.753692 176.5,34.49999 143.5,32.499975 142.5,13.499841 130.5,28.499946 137.5,41.500036 135.5,51.500106 117.5,52.500113 99.5,54.500126 116.5,39.500022 z" Stretch="Fill" Stroke="{x:Null}">
<Path.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Path.Fill>
</Path>
<ContentPresenter HorizontalAlignment="Right" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Top" Margin="0,24.52,18.715,0"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True"/>
<Trigger Property="IsDefaulted" Value="True"/>
<Trigger Property="IsMouseOver" Value="True"/>
<Trigger Property="IsPressed" Value="True"/>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
अब बटन का उपयोग करें:
यहाँ एक उदाहरण है आपके पास पीएनजी को xaml में बदलने की क्षमता है।
धन्यवाद, लेकिन मेरे पास मिश्रण नहीं है। हालांकि, मुझे लगता है कि यह मेरी समस्या का समाधान नहीं करेगा क्योंकि डब्ल्यूपीएफ अभी भी हिट परीक्षण के लिए आयताकार क्षेत्र का उपयोग करेगा, मेरी छवि के पारदर्शी पिक्सेल का सम्मान नहीं करेगा। क्या मैं सही हू? मैंने एक विधि लिखकर समस्या हल की जो जांचता है कि क्या माउसLeftButtonDown ईवेंट हैंडलर में छवि का एक पारदर्शी पिक्सेल मारा गया था। लेकिन मुझे आश्चर्य है कि क्या एक बेहतर, अधिक सामान्य समाधान है। –
मीकल, यह छवि के साथ मामला हो सकता है, मुझे अभी तक यकीन नहीं है, लेकिन पथ या ज्यामिति का उपयोग करके आप इसे अधिक सरल बना सकते हैं। मैं आपको एक पूर्ण उदाहरण प्रदान करने के लिए अपना उत्तर संपादित कर रहा हूं। –