MultiMathExpressionConverter
사용자가 MultiMathExpressionConverter
을 사용하여 여러 값으로 다양한 수학 연산을 수행할 수 있는 변환기입니다 MultiBinding
.
여러 Convert
변수를 사용하여 정의된 식 문자열을 ConverterParameter
계산하고 결과를 반환 double
합니다.
변환기로 전달되는 값의 이름은 x?
??입니다. 는 식에 정의된 MultiBinding
순서입니다. 식의 다른 변수 이름은 무시됩니다. 예를 들어 (power = volts * amps)의 P = V * I
계산을 표현하려면 다음을 작성할 수 있습니다.
<Label.Text>
<MultiBinding Converter="{StaticResource MultiMathExpressionConverter}" ConverterParameter="x0 * x1">
<Binding Path="Volts" />
<Binding Path="Amps" />
</MultiBinding>
</Label.Text>
구문
다음 예제에서는 정의 순서대로 값을 제공할 위치의 x0 + x1 + x2
결과를 보여 주는 x
a를 MultiBinding
추가하는 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>
MultiMathExpressionConverter 사용
XAML MultiMathExpressionConverter
에서 다음과 같이 사용할 수 있습니다.
<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.MultiMathExpressionConverterPage">
<ContentPage.Resources>
<ResourceDictionary>
<toolkit:MultiMathExpressionConverter x:Key="MultiMathExpressionConverter" />
</ResourceDictionary>
</ContentPage.Resources>
<Label HorizontalOptions="Center">
<Label.Text>
<MultiBinding Converter="{StaticResource MultiMathExpressionConverter}" ConverterParameter="x0 + x1 + x2">
<Binding Path="X0" />
<Binding Path="X1" />
<Binding Path="X2" />
</MultiBinding>
</Label.Text>
</Label>
</ContentPage>
C#
MultiMathExpressionConverter
C#에서 다음과 같이 사용할 수 있습니다.
class MultiMathExpressionConverterPage : ContentPage
{
public MultiMathExpressionConverterPage()
{
var label = new Label
{
HorizontalOptions = LayoutOptions.Center
};
label.SetBinding(
Label.TextProperty,
new MultiBinding
{
Converter = new MultiMathExpressionConverter(),
ConverterParameter = "x0 + x1 + x2",
Bindings = new List<BindingBase>
{
new Binding(nameof(ViewModel.X0)),
new Binding(nameof(ViewModel.X1)),
new Binding(nameof(ViewModel.X2))
}
});
Content = label;
}
}
C# 태그
이 CommunityToolkit.Maui.Markup
패키지는 C#에서 이 변환기를 사용하는 훨씬 더 간결한 방법을 제공합니다.
class MultiMathExpressionConverterPage : ContentPage
{
public MultiMathExpressionConverterPage()
{
Content = new Label()
.CenterHorizontal()
.Bind(
Label.TextProperty,
new List<BindingBase>
{
new Binding(nameof(ViewModel.X0)),
new Binding(nameof(ViewModel.X1)),
new Binding(nameof(ViewModel.X2))
},
converter: new MultiMathExpressionConverter(),
converterParameter: "x0 + x1 + x2");
}
}
지원되는 작업
지원되는 작업은 다음과 같습니다.
- "+"
- "-"
- "*"
- "/"
- "%"
- "abs"
- "acos"
- "asin"
- "atan"
- "atan2"
- "ceiling"
- "cos"
- "cosh"
- "exp"
- "floor"
- "ieeere기본der"
- "로그"
- "log10"
- "max"
- "min"
- "pow"
- "round"
- "sign"
- "sin"
- "sinh"
- "sqrt"
- "tan"
- "tanh"
- "잘림"
- "^"
- "pi"
- "e"
예제
.NET MAUI 커뮤니티 도구 키트 샘플 애플리케이션에서 작동 중인 이 변환기의 예를 찾을 수 있습니다.
API
.NET MAUI 커뮤니티 도구 키트 GitHub 리포지토리에서 오버에 대한 MultiMathExpressionConverter
소스 코드를 찾을 수 있습니다.
.NET MAUI Community Toolkit
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기