gpt4 book ai didi

c# - bool 到图像转换器不起作用。图像不变

转载 作者:行者123 更新时间:2023-12-03 10:41:57 25 4
gpt4 key购买 nike

我已经有一个运行中的bool到图像转换器,可以在另一个应用程序上完美运行。我已经复制并修改了代码,但无法正常工作。你们有个主意吗?

我的XAML:

    <Grid>
<Grid.Resources>
<ResourceDictionary>
<services:BooleanToObjectConverterService x:Key="boolToStyleImage"
x:TypeArguments="Style">
<services:BooleanToObjectConverterService.FalseObject>
<Style TargetType="Image">
<Setter Property="Source" Value="container_noconnect.png" />
</Style>
</services:BooleanToObjectConverterService.FalseObject>
<services:BooleanToObjectConverterService.TrueObject>
<Style TargetType="Image">
<Setter Property="Source" Value="container_withconnect.png" />
</Style>
</services:BooleanToObjectConverterService.TrueObject>
</services:BooleanToObjectConverterService>
</ResourceDictionary>
</Grid.Resources>
<Image Style="{Binding HasWebserviceConnection, Converter={StaticResource boolToStyleImage}}" Aspect="AspectFill"/>
</Grid>

这些是我的类(class): BooleanToObjectConverterService:
    public class BooleanToObjectConverterService<T> : IValueConverter
{
public T FalseObject { set; get; }

public T TrueObject { set; get; }

public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
return (bool)value ? this.TrueObject : this.FalseObject;
}

public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
return ((T)value).Equals(this.TrueObject);
}
}

ImageResourceExtension:

[ContentProperty("Source")]
public class ImageResourceExtension : IMarkupExtension
{
public string Source { get; set; }

public object ProvideValue(IServiceProvider serviceProvider)
{
if (Source == null)
return null;
var imageSource = ImageSource.FromResource(Source);
return imageSource;
}
}

我已经调试了代码,并且 HasWebserviceConnection正确更改了值。

编辑:
感谢@Janne Matikainen,我使用了DataTriggers,现在可以使用了。我明天要更新解决方案。
谢谢

最佳答案

就那么简单。谢谢@Janne Matikainen。

<Image x:Name="image" Source="container_noconnect.png" Aspect="AspectFill" >
<Image.Triggers>
<DataTrigger TargetType="Image" Binding="{Binding Source={x:Reference advanceButton}, IsEnabled}" Value="True">
<Setter Property="Source" Value="container_withconnect" />
</DataTrigger>
</Image.Triggers>
</Image>

关于c# - bool 到图像转换器不起作用。图像不变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58028609/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com