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 Color
value
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 BaseConverter
uygulanır:
Özellik | Açıklama |
---|---|
DefaultConvertReturnValue |
Bir Exception oluştururken IValueConverter.Convert(object?, Type, object?, CultureInfo?) döndürülecek varsayılan değer. CommunityToolkit.Maui.Options olarak ayarlandığında true bu değer kullanılır..ShouldSuppressExceptionsInConverters |
DefaultConvertBackReturnValue |
Bir Exception oluştururken IValueConverter.ConvertBack(object?, Type, object?, CultureInfo?) döndürülecek varsayılan değer. CommunityToolkit.Maui.Options olarak ayarlandığında true bu değer kullanılır..ShouldSuppressExceptionsInConverters |
ICommunityToolkitValueConverter Özellikleri
aşağıdaki özellikler içinde public interface ICommunityToolkitValueConverter
uygulanır:
Özellik | Türü | Açıklama |
---|---|---|
DefaultConvertReturnValue |
object? |
Bir Exception oluştururken IValueConverter.Convert(object?, Type, object?, CultureInfo?) döndürülecek varsayılan değer. CommunityToolkit.Maui.Options olarak ayarlandığında true bu değer kullanılır..ShouldSuppressExceptionsInConverters |
DefaultConvertBackReturnValue |
object? |
Bir Exception oluştururken IValueConverter.ConvertBack(object?, Type, object?, CultureInfo?) döndürülecek varsayılan değer. CommunityToolkit.Maui.Options olarak ayarlandığında true bu değer kullanılır..ShouldSuppressExceptionsInConverters |
Sözdizimi
Aşağıdaki örneklerde, belirli Color
bir 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 ColorToCmykStringConverter
kaynak kodunu .NET MAUI Community Toolkit GitHub deposunda bulabilirsiniz.
.NET MAUI Community Toolkit
Geri Bildirim
https://aka.ms/ContentUserFeedback.
Çok yakında: 2024 boyunca, içerik için geri bildirim mekanizması olarak GitHub Sorunları’nı kullanımdan kaldıracak ve yeni bir geri bildirim sistemiyle değiştireceğiz. Daha fazla bilgi için bkz.Gönderin ve geri bildirimi görüntüleyin