私は次のシナリオを持っています...
<Page.Resources>
<converters:EnumToBoolean x:Key="Empty" Expected="Empty"/>
<converters:EnumToBoolean x:Key="Full" Expected="Full"/>
</Page.Resources>
.
.
.
<SomeControl IsChecked="{x:Bind ViewModel.State, Converter={StaticResource Empty}, Mode=TwoWay}"/>
<SomeControl IsChecked="{x:Bind ViewModel.State, Converter={StaticResource Full}, Mode=TwoWay}"/>
EnumToBoolean
IValueConverter
ac# を に変換enum
するですboolean
。
Expected
値を使用して、ViewModel.State
真か偽かを判断します。これはConvert
一部でIValueConverter
あり、機能しますが、特別なことは何もありません。
ただし、'boolean' 値が false の場合、ConvertBack
元の値を結果として返す必要があります。ViewModel.State
期待どおり「null」を返すと、実行時例外が発生します。
コンバーターの関数のOriginal
値を取得するために、次の 2 つの方法を試しました。ConvertBack
a)別のフィールドを追加Original
し、それをバインドしようとしました
<converters:EnumToBoolean x:Key="Empty" Expected="Empty" Original="{x:Bind ViewModel.State, Mode=OneWay}"/>
<converters:EnumToBoolean x:Key="Full" Expected="Full" Original="{x:Bind ViewModel.State, Mode=OneWay}"/>
これはコンパイルおよび実行されますが、実行時例外が発生します。コンバーターがインスタンス化される前にコンバーターにバインドしようとするため
ConverterParameter
b)バインディングが埋め込まれた a として渡そうとしました
<SomeControl IsChecked="{x:Bind ViewModel.State, Converter={StaticResource Empty}, ConverterParameter={x:Bind ViewModel.WallPainter, Mode=OneWay}, Mode=TwoWay}"/>
<SomeControl IsChecked="{x:Bind ViewModel.State, Converter={StaticResource Full}, ConverterParameter={x:Bind ViewModel.WallPainter, Mode=OneWay}, Mode=TwoWay}"/>
これはまったくコンパイルされません。エラーコードやここまたはGoogleでのヒットなしで、説明のないエラーで失敗します...「イベント値は行境界を越えて分割できません」
これらのシナリオのいずれかを機能させる方法について誰か提案がありますか?
注-私の一時的な解決策は、理想とはほど遠いものです Original
が、コンバーターのフィールドを作成し 、コード ビハインドでpublic Func<TEnum> Original { get; set; }
そのゲッターを設定することです。 function
このオプションは、バインディングの実装戦略を断片化するため、気にしません。