He creado una imagen dentro de un ButtonStyle. Ahora he creado una propiedad adjunta para poder establecer el origen para esa imagen. Debería ser sencillo pero estoy atascado con eso.Cómo utilizar la propiedad adjunta dentro de un estilo?
Ésta es mi ButtonStyle acortada:
<Style x:Key="ToolBarButtonStyle"
TargetType="Button">
...
<Image x:Name="toolbarImage"
Source="{TemplateBinding PrismExt:ImageSourceAttachable:ImageSource}"
Width="48"
Height="48" />
...
</Style>
Y esta es la definición de la propiedad adjunto, Tenga en cuenta que no tengo ni idea de cómo solucionar la devolución de llamada, como el DependencyProperty parece ser el botón en lugar de la imagen. Y el botón no expone mi imagen dentro de su estilo. Es complicado.
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()));
}
}
}
Éste es cómo establecer la fuente de imagen dentro de XAML:
<Button PrismExt:ImgSourceAttachable.ImgSource="./Images/New.png"
Style="{StaticResource ToolBarButtonStyle}" />
alguna idea por favor? Muchas gracias,
creo que respondí a poco aquí, ¿desea establecer la propiedad a través de una incubadora y luego se unirá a él dentro de la plantilla? –
La vista representa cuatro botones de una barra de herramientas como esta: http://sl.venuscloud.com/ Me gustaría inyectar la ruta al icono de cada botón desde la vista hacia la plantilla a través de la propiedad adjunta. Espero que esto lo haga más claro. Gracias – Houman