Я создал изображение в ButtonStyle. Теперь я создал Attached Property, чтобы я мог установить источник для этого изображения. Должно быть прямо, но я застрял с этим.
Это мой сокращенный ButtonStyle:
<Style x:Key="ToolBarButtonStyle"
TargetType="Button">
...
<Image x:Name="toolbarImage"
Source="{TemplateBinding PrismExt:ImageSourceAttachable:ImageSource}"
Width="48"
Height="48" />
...
</Style>
И это определение прикрепленного свойства. Обратите внимание, что я понятия не имею, как исправить обратный вызов, так как свойство dependency кажется кнопкой вместо изображения. И Баттон не выставляет мое изображение в своем стиле. Это сложно.
namespace SalesContactManagement.Infrastructure.PrismExt
{
public class ImgSourceAttachable
{
public static void SetImgSource(DependencyObject obj, string imgSource)
{
obj.SetValue(ImgSourceProperty, imgSource);
}
public static string GetImgSource(DependencyObject obj)
{
return obj.GetValue(ImgSourceProperty).ToString();
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ImgSourceProperty =
DependencyProperty.RegisterAttached("ImgSource", typeof(string), typeof(ImgSourceAttachable), new PropertyMetadata(Callback));
private static void Callback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
//((Button)d).Source = new BitmapImage(new Uri(Application.Current.Host.Source, e.NewValue.ToString()));
}
}
}
Вот как я устанавливаю источник изображения в XAML:
<Button PrismExt:ImgSourceAttachable.ImgSource="./Images/New.png"
Style="{StaticResource ToolBarButtonStyle}" />
Есть идеи, пожалуйста?
Большое спасибо,