Ich habe eine Schaltfläche mit einem festen Hintergrundbild und möchte ein kleines Overlay-Bild darüber anzeigen. Welches Overlay-Bild ausgewählt wird, hängt von einer Abhängigkeitseigenschaft (LapCounterPingStatus
) des entsprechenden Viewmodels ab.datatrigger on enum um das Bild zu ändern
Das ist, was ich bisher habe:
<Button>
<Grid>
<Image Stretch="None"> <!-- Background Image -->
<Image.Style>
<Style TargetType="{x:Type Image}">
<Setter Property="Source" Value="/Images/Pingn.png"/>
</Style>
</Image.Style>
</Image>
<Image Stretch="None" Panel.ZIndex="1"> <!-- Small Overlay Image -->
<Image.Style>
<Style TargetType="{x:Type Image}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=LapCounterPingStatus}" Value="PingStatus.PING_UNKNOWN">
<Setter Property="Source" Value="/Images/RefreshOverlayn.png"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=LapCounterPingStatus}" Value="PingStatus.PING_FAILURE">
<Setter Property="Source" Value="/Images/ErrorOverlayn.png"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=LapCounterPingStatus}" Value="PingStatus.PING_SUCCESS">
<Setter Property="Source" Value="/Images/CheckmarkOverlayn.png"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
</Grid>
</Button>
Relevante Teile meiner Viewmodel
public class ConfigurationViewModel
{
public enum PingStatus { PING_UNKNOWN, PING_SUCCESS, PING_FAILURE };
public PingStatus LapCounterPingStatus
{
get { return _lapCounterPingStatus; }
set
{
_lapCounterPingStatus = value;
RaisePropertyChanged(LapCounterPingStatusPropertyName);
}
}
}
Gerade jetzt, überhaupt kein Overlay-Bild wird angezeigt. Was könnte falsch sein?
UPDATE
Trace-Fenster meiner IDE ist System.ArgumentException
und System.FormatException
zeigt. Konnte die Problemquelle ein unbekannter Enumerationstyp PingStatus
im XAML sein?
Verwandte: http : //stackoverflow.com/q/10250925/590790 Obwohl dieser Typ es schon funktioniert hat Ady. –