Share via


ColorToCmykStringConverter

, ColorToCmykStringConverter kullanıcıların bir değer bağlamasını CMYK string eşdeğerine biçiminde dönüştürmesine olanak tanıyan tek yönlü bir Color dönüştürücüdür: CMYK(camgöbeği, eflatun, sarı,anahtar), burada camgöbeği, eflatun, sarı ve anahtar %0 ile %100 arasında bir değer olur (örneğin CMYK(%0,%100,%100%,0).Colors.Red

yöntemi, Convert sağlanan Colorvalue cmyk string eşdeğerine dönüştürülen döndürür.

ConvertBack yöntemi desteklenmez.

BaseConverter Özellikleri

Aşağıdaki özellikler temel sınıfında public abstract class BaseConverteruygulanır:

Özellik Açıklama
DefaultConvertReturnValue Bir Exceptionoluştururken IValueConverter.Convert(object?, Type, object?, CultureInfo?) döndürülecek varsayılan değer. CommunityToolkit.Maui.Options olarak ayarlandığında truebu değer kullanılır..ShouldSuppressExceptionsInConverters
DefaultConvertBackReturnValue Bir Exceptionoluştururken IValueConverter.ConvertBack(object?, Type, object?, CultureInfo?) döndürülecek varsayılan değer. CommunityToolkit.Maui.Options olarak ayarlandığında truebu değer kullanılır..ShouldSuppressExceptionsInConverters

ICommunityToolkitValueConverter Özellikleri

aşağıdaki özellikler içinde public interface ICommunityToolkitValueConverteruygulanır:

Özellik Türü Açıklama
DefaultConvertReturnValue object? Bir Exceptionoluştururken IValueConverter.Convert(object?, Type, object?, CultureInfo?) döndürülecek varsayılan değer. CommunityToolkit.Maui.Options olarak ayarlandığında truebu değer kullanılır..ShouldSuppressExceptionsInConverters
DefaultConvertBackReturnValue object? Bir Exceptionoluştururken IValueConverter.ConvertBack(object?, Type, object?, CultureInfo?) döndürülecek varsayılan değer. CommunityToolkit.Maui.Options olarak ayarlandığında truebu değer kullanılır..ShouldSuppressExceptionsInConverters

Sözdizimi

Aşağıdaki örneklerde, belirli Colorbir cmyk eşdeğer dizesini görüntülemek için öğesinin nasıl kullanılacağı ColorToCmykStringConverter gösterilmektedir.

XAML

XAML ad alanını dahil edin

Araç setini XAML'de kullanmak için sayfanıza veya görünümünüzde aşağıdakilerin xmlns eklenmesi gerekir:

xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"

Bu nedenle aşağıdakiler:

<ContentPage
    x:Class="CommunityToolkit.Maui.Sample.Pages.MyPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

</ContentPage>

aşağıdakiler dahil xmlns edilecek şekilde değiştirilir:

<ContentPage
    x:Class="CommunityToolkit.Maui.Sample.Pages.MyPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit">

</ContentPage>

ColorToCmykStringConverter Kullanma

ColorToCmykStringConverter XAML'de aşağıdaki gibi kullanılabilir:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
             x:Class="CommunityToolkit.Maui.Sample.Pages.Converters.ColorToCmykStringConverterPage">

    <ContentPage.Resources>
        <ResourceDictionary>
            <toolkit:ColorToCmykStringConverter x:Key="ColorToCmykStringConverter" />
        </ResourceDictionary>
    </ContentPage.Resources>

    <VerticalStackLayout>
        <Label Text="My favourite Color is:" />

        <Label Text="{Binding MyFavoriteColor, Converter={StaticResource ColorToCmykStringConverter}}" />
    </VerticalStackLayout>

</ContentPage>

C#

ColorToCmykStringConverter C# dilinde aşağıdaki gibi kullanılabilir:

class ColorToCmykStringConverterPage : ContentPage
{
    public ColorToCmykStringConverterPage()
    {
        var label = new Label();

	label.SetBinding(
		Label.TextProperty,
		new Binding(
			nameof(ViewModel.MyFavoriteColor),
			converter: new ColorToCmykStringConverter()));

	Content = new VerticalStackLayout
	{
		Children =
		{
			new Label { Text = "My favourite Color is:" },
			label
		}
	};
    }
}

C# İşaretlemeyi

Paketimiz CommunityToolkit.Maui.Markup , C# dilinde bu dönüştürücüsü kullanmak için çok daha kısa bir yol sağlar.

using CommunityToolkit.Maui.Markup;

class ColorToCmykStringConverterPage : ContentPage
{
    public ColorToCmykStringConverterPage()
    {
        Content = new VerticalStackLayout
        {
            Children =
            {
                new Label()
                    .Text("My favourite Color is:"),
                new Label()
                    .Bind(
                        Label.TextProperty,
                        static (ViewModel vm) => vm.MyFavoriteColor,
                        converter: new ColorToCmykStringConverter())
            }
        };
    }
}

Örnekler

Bu dönüştürücüye ilişkin bir örneği .NET MAUI Community Toolkit Örnek Uygulamasında bulabilirsiniz.

API

üzerinde için ColorToCmykStringConverterkaynak kodunu .NET MAUI Community Toolkit GitHub deposunda bulabilirsiniz.