ho creato la mia proprietà associata in questo modo:Style Trigger su allegata proprietà
public static class LabelExtension
{
public static bool GetSelectable(DependencyObject obj)
{
return (bool)obj.GetValue(SelectableProperty);
}
public static void SetSelectable(DependencyObject obj, bool value)
{
obj.SetValue(SelectableProperty, value);
}
// Using a DependencyProperty as the backing store for Selectable. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SelectableProperty =
DependencyProperty.RegisterAttached("Selectable", typeof(bool), typeof(Label), new UIPropertyMetadata(false));
}
E poi sto cercando di creare uno stile con un trigger che dipende da questo:
<!--Label-->
<Style TargetType="{x:Type Label}">
<Style.Triggers>
<Trigger Property="Util:LabelExtension.Selectable" Value="True">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Label}">
<TextBox IsReadOnly="True" Text="{TemplateBinding Content}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
ma sto ottenendo un tempo di un'eccezione run:
Cannot convert the value in attribute 'Property' to object of type 'System.Windows.DependencyProperty'. Error at object 'System.Windows.Trigger' in markup file
Come posso accedere al valore della proprietà associata in un trigger stile? Ho provato a utilizzare un DataTrigger con un'associazione RelativeSource, ma non stava ottenendo il valore.
Grazie, ho lavorato fuori che cambiando il tipo di proprietario di opporsi risolto il problema, ma non ho capito perché. –