4
I have an item that should change the images as an old value check and new value is happening. I have a part of the codes ready and the images of Static Resources. But, I am locked on how to proceed from here
I have this code that indicates the difference in values.
public enum Deviation
{
None = 0,
Up = 1,
Down = 2
}
public bool ShowDifference { get; set; }
public double ShouldShowDifference
{
get => // colocar a chamada de verificação e determinação de imagem com o metodo de ValorAlterado
set => _showDifference = value;
}
public Deviation ValorAlterado
{
get
{
if (Value == ValorAnterior)
return Deviation.None;
return Value > ValorAnterior? Deviation.Up : Deviation.Down;
}
}
double ValorAnterior{ get; set; } = double.NaN;
public double Value
{
get => _value;
set
{
this.ValorAnterior = _value;
_value = value;
}
}
And I need this indication to go to this shampooing, stating that for the deviation condition with UP the Static Resource must be Icons.Buttons.Up and for DOWN it must be Icons.Buttons.Down
<Image Source="{StaticResource Icons.Buttons.Down}" Height="20" Width="20"/>
I’m still developing how to form the bindings and the like, so I’m a little lost on how to join these parts that I developed with the overall goal.
---------- UPDATE AFTER BRUNO’S REPLY
Code I did, when debugging works properly, the problem is now only the image appear correctly.
public Image DeviationImage
{
get
{
if (ShowDifference)
{
switch ((double)ValueIncreased)
{
case 1:
return (Image)Application.Current.Resources["ArrowUp"];
case 2:
return (Image)Application.Current.Resources["ArrowDown"];
case 0:
return (Image)Application.Current.Resources["ArrowEqual"];
}
}
return null;
}
}
XAML - Where will I put the image
<Image Source="{Binding DeviationImage}" Height="20" Width="20"/>
XAML - Resources no xaml
<Image x:Key="ArrowUp" Source="{telerik:RadGlyph Glyph='', Foreground='Blue'}"/>
<Image x:Key="ArrowDown" Source="{telerik:RadGlyph Glyph='', Foreground='Blue'}"/>
<Image x:Key="ArrowEqual" Source="{telerik:RadGlyph Glyph='', Foreground='Blue'}"/>
</UserControl.Resources>
I really appreciate the help! Could you tell me, how to return my image? it is a Static Resource Icons.Buttons.Down and Icons.Buttons.Up
– OlivF
I updated the question with the new code
– OlivF
@Olivf I updated the answer. It should be clearer now. Also because my previous answer was a bit far from the right answer.
– Bruno Costa
Thank you Bruno, your reply helped me a lot. I managed, I changed some points using a convert.
– OlivF