What I m trying to accomplish
缩略语 观点代码>,我列出了物体清单。 每个展览会都有一个旁边的检查箱。
理想的情况是,当用户检查或检查时,检查箱一采用一种方法,使我能够与目标站在一起:
以上是无耻的法典。
The actual code
在现实中,当用户检查/核对箱子时,该代码只采用一种方法,只有Im通过这个标码
I need to convert that object ChcekedChangedEventArgs
into a bool. (Note that I m using the MvvM
pattern, so I m not working with code-behind.)
A kind soul gave me some code that will probably do the converting:
public class CheckedChangedArgsConverter : BaseConverterOneWay<CheckedChangedEventArgs, bool>
{
public override bool DefaultConvertReturnValue { get; set; } = false;
public override bool ConvertFrom(CheckedChangedEventArgs value, CultureInfo culture)
{
return value.Value;
}
}
然而,我不知道如何使用转换器。 我在此似乎有两个选择:
- Run the converter from the Xaml and have it run before the command
AddRemoveFromList
is called so I can pass in the converted Boolean, or - Run the converter code from the C# class, something like this:
事实是,我不知道如何做<>要么是。 谁能帮助?
================================================================================================================================================================================================================================================================
EDIT:标的<代码>ChangedEventArgs通过成为C#方法的,是ALWAYS。
Here s my Checkbox
code. I m using the EventToCommandBehavior
because it s the only thing I can think of to call a command from inside the Checkbox:
<CheckBox x:Name="checkBox"
ScaleX="1.5"
ScaleY="1.5"
Color="#000063"
HorizontalOptions="End">
<CheckBox.Behaviors>
<toolkit:EventToCommandBehavior EventName="CheckedChanged"
Command="{Binding Source={x:Reference this},
Path=BindingContext.AddRemoveFromListCommand}"/>
</CheckBox.Behaviors>
</CheckBox>
我在核对箱中添加了<代码>x:TypeArguments:
<CheckBox x:Name="checkBox"
ScaleX="1.5"
ScaleY="1.5"
Color="#000063"
HorizontalOptions="End">
<CheckBox.Behaviors>
<toolkit:EventToCommandBehavior
x:TypeArguments="CheckedChangedEventArgs"
EventName="CheckedChanged"
Command="{Binding Source={x:Reference this}, Path=BindingContext.AddRemoveFromListCommand}" />
</CheckBox.Behaviors>
</CheckBox>
而这正是骗局。