Last active
December 19, 2015 15:09
-
-
Save JohanLarsson/5974239 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class AttachedProperties | |
{ | |
public static readonly DependencyProperty IconProperty = DependencyProperty.RegisterAttached( | |
"Icon", | |
typeof (StreamGeometry), | |
typeof (AttachedProperties), | |
new PropertyMetadata(default(StreamGeometry)) | |
); | |
public static void SetIcon(UIElement element, StreamGeometry value) | |
{ | |
element.SetValue(IconProperty, value); | |
} | |
public static StreamGeometry GetIcon(UIElement element) | |
{ | |
return (StreamGeometry)element.GetValue(IconProperty); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="ImagesPanelTemp.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:local="clr-namespace:ImagesPanelTemp" | |
Title="MainWindow" SizeToContent="WidthAndHeight"> | |
<Window.Resources> | |
<Style x:Key="ImageButton" TargetType="{x:Type Button}"> | |
<Setter Property="HorizontalContentAlignment" Value="Stretch" /> | |
<Setter Property="ContentTemplate"> | |
<Setter.Value> | |
<DataTemplate> | |
<Grid> | |
<Path Data="{Binding Path=(local:AttachedProperties.Icon), RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Button}}}" | |
HorizontalAlignment="Left" Margin="8,0,0,0" Height="100" Width="100" Fill="Blue" Stretch="UniformToFill" Stroke="Red" StrokeThickness="6"/> | |
<TextBlock Text="{TemplateBinding Content}" HorizontalAlignment="Center" /> | |
</Grid> | |
</DataTemplate> | |
</Setter.Value> | |
</Setter> | |
</Style> | |
</Window.Resources> | |
<Grid> | |
<Button Content="Test" local:AttachedProperties.Icon="M1,0 1,1 0,1 z" Style="{StaticResource ImageButton}"/> | |
</Grid> | |
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Button Content="Pressing" local:AttachedProperties.Icon="{StaticResource Picka}" Style="{StaticResource ImageButton}"/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment