VariableMultiValueConverter
사용자가 VariableMultiValueConverter
값을 단일 bool
값으로 변환 bool
MultiBinding
할 수 있는 변환기입니다. 이렇게 하려면 ConditionType에 지정된 대로 All, Any, None 또는 특정 수의 값이 true인지 여부를 지정할 수 있습니다.
이 메서드는 Convert
정의된 결과에 따라 ConditionType
제공된 values
변환된 결과를 전체 bool
결과로 반환합니다.
메서드는 ConvertBack
로 설정된 경우에만 ConditionType
결과를 반환합니다 MultiBindingCondition.All
.
BaseConverter 속성
다음 속성은 기본 클래스 public abstract class BaseConverter
에서 구현됩니다.
속성 | 설명 |
---|---|
DefaultConvertReturnValue |
을 throw할 때 IValueConverter.Convert(object?, Type, object?, CultureInfo?) 반환할 기본값입니다 Exception . 이 값은 CommunityToolkit.Maui.Options.ShouldSuppressExceptionsInConverters 가 로 설정된 true 경우에 사용됩니다. |
DefaultConvertBackReturnValue |
을 throw할 때 IValueConverter.ConvertBack(object?, Type, object?, CultureInfo?) 반환할 기본값입니다 Exception . 이 값은 CommunityToolkit.Maui.Options.ShouldSuppressExceptionsInConverters 가 로 설정된 true 경우에 사용됩니다. |
ICommunityToolkitValueConverter 속성
다음 속성은 다음에서 구현됩니다.public interface ICommunityToolkitValueConverter
속성 | Type | 설명 |
---|---|---|
DefaultConvertReturnValue |
object? |
을 throw할 때 IValueConverter.Convert(object?, Type, object?, CultureInfo?) 반환할 기본값입니다 Exception . 이 값은 CommunityToolkit.Maui.Options.ShouldSuppressExceptionsInConverters 가 로 설정된 true 경우에 사용됩니다. |
DefaultConvertBackReturnValue |
object? |
을 throw할 때 IValueConverter.ConvertBack(object?, Type, object?, CultureInfo?) 반환할 기본값입니다 Exception . 이 값은 CommunityToolkit.Maui.Options.ShouldSuppressExceptionsInConverters 가 로 설정된 true 경우에 사용됩니다. |
구문
다음 예제에서는 2개 이상의 값 MultiBinding
이 true로 Label
평가되는 경우 표시할 수 없는 값을 만드는 방법을 보여 줍니다.
XAML
XAML 네임스페이스 포함
XAML에서 도구 키트를 사용하려면 페이지 또는 보기에 다음 xmlns
을 추가해야 합니다.
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
따라서 다음을 수행합니다.
<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>
다음과 같이 포함 xmlns
하도록 수정됩니다.
<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>
VariableMultiValueConverter 사용
XAML VariableMultiValueConverter
에서 다음과 같이 사용할 수 있습니다.
<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.VariableMultiValueConverterPage">
<ContentPage.Resources>
<ResourceDictionary>
<toolkit:VariableMultiValueConverter
x:Key="VariableMultiValueConverter"
ConditionType="LessThan"
Count="2" />
</ResourceDictionary>
</ContentPage.Resources>
<Label Text="At least 2 toppings must be selected.">
<Label.IsVisible>
<MultiBinding Converter="{StaticResource VariableMultiValueConverter}">
<Binding Path="IsCheeseSelected" />
<Binding Path="IsHamSelected" />
<Binding Path="IsPineappleSelected" />
</MultiBinding>
</Label.IsVisible>
</Label>
</ContentPage>
C#
VariableMultiValueConverter
C#에서 다음과 같이 사용할 수 있습니다.
class VariableMultiValueConverterPage : ContentPage
{
public VariableMultiValueConverterPage()
{
var label = new Label
{
Text = "At least 2 toppings must be selected."
};
label.SetBinding(
Label.IsVisibleProperty,
new MultiBinding
{
Converter = new VariableMultiValueConverter
{
ConditionType = MultiBindingCondition.LessThan,
Count = 2
},
Bindings = new List<BindingBase>
{
new Binding(nameof(ViewModel.IsCheeseSelected)),
new Binding(nameof(ViewModel.IsHamSelected)),
new Binding(nameof(ViewModel.IsPineappleSelected))
}
});
Content = label;
}
}
C# 태그
이 CommunityToolkit.Maui.Markup
패키지는 C#에서 이 변환기를 사용하는 훨씬 더 간결한 방법을 제공합니다.
using CommunityToolkit.Maui.Markup;
class VariableMultiValueConverterPage : ContentPage
{
public VariableMultiValueConverterPage()
{
Content = new Label()
.Text("At least 2 toppings must be selected.")
.Bind(
Label.IsVisibleProperty,
new List<BindingBase>
{
new Binding(nameof(ViewModel.IsCheeseSelected)),
new Binding(nameof(ViewModel.IsHamSelected)),
new Binding(nameof(ViewModel.IsPineappleSelected))
},
converter: new VariableMultiValueConverter
{
ConditionType = MultiBindingCondition.LessThan,
Count = 2
});
}
}
속성
속성 | Type | 설명 |
---|---|---|
ConditionType | MultiBindingCondition |
에서 제공된 부울 값에서 벗어나야 하는 true 값 MultiBinding 수를 나타냅니다. |
Count | int |
또는 Exact .를 사용할 ConditionType 때 true여야 하는 값의 GreaterThan LessThan 수입니다. |
MultiBindingCondition
MultiBindingCondition
열거형은 다음 멤버를 정의합니다.
None
- 값 중 어느 것도 true가 되어서는 안 됩니다.All
- 모든 값이 true여야 합니다.Any
- 모든 값은 true여야 합니다.Exact
- 속성에Count
구성된 정확한 숫자는 true여야 합니다.GreaterThan
- 속성에 구성된Count
숫자가 true여야 합니다.LessThan
- 속성에 구성된 숫자보다 작음은Count
true여야 합니다.
예제
.NET MAUI 커뮤니티 도구 키트 샘플 애플리케이션에서 작동 중인 이 변환기의 예를 찾을 수 있습니다.
API
.NET MAUI 커뮤니티 도구 키트 GitHub 리포지토리에서 오버에 대한 VariableMultiValueConverter
소스 코드를 찾을 수 있습니다.
.NET MAUI Community Toolkit
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기