特定のボタンの表示を切り替えるために、CurrentUser のアクセス許可レベルを列挙型のアクセス許可のサブセットと比較する MultiConverter を作成しようとしました。私のコンバーターは、UserControl の作成時に起動時に呼び出されますが、その後 CurrentUser のレベルを変更すると、コンバーターは再度呼び出されません。
基本的な構造は次のとおりです。
KioskController は UserInfo を所有し、CurrentUser は Level を所有しています。CurrentUser.Level にバインドして更新しています。重要なスニペットは次のとおりです。
<Image x:Name="Redeem" Height="114" Width="178" Source="Graphics\MAINMENU_Redeem.png" Margin="128,260,718,394">
<Image.Visibility>
<MultiBinding Converter="{StaticResource theIntPermissionToVisibilityConverter}">
<Binding Path="_UserInfo.CurrentUser.Level"/>
<Binding Source="{x:Static local:UserInfo+UserLevel.Cashier}"/>
<Binding Source="{x:Static local:UserInfo+UserLevel.Manager}"/>
<Binding Source="{x:Static local:UserInfo+UserLevel.Tech}"/>
</MultiBinding>
</Image.Visibility>
</Image>
キオスクコントローラー:
public sealed class KC : DependencyObject
{
/// <summary>
/// Singleton interface to the Kiosk Controller
/// </summary>
///
#region _UserInfoDependencyProperty
public UserInfo _UserInfo
{
get { return (UserInfo)this.GetValue(_UserInfoProperty); }
set { this.SetValue(_UserInfoProperty, value); }
}
public static readonly DependencyProperty _UserInfoProperty = DependencyProperty.Register(
"_UserInfo", typeof(UserInfo), typeof(KC), new PropertyMetadata(null));
#endregion
UserInfo クラス:
public class UserInfo : DependencyObject
{
#region CurrentUserProperty
public User CurrentUser
{
get { return (User)this.GetValue(CurrentUserProperty); }
set { this.SetValue(CurrentUserProperty, value); }
}
public static readonly DependencyProperty CurrentUserProperty = DependencyProperty.Register(
"CurrentUser", typeof(User), typeof(UserInfo), new PropertyMetadata(null));
#endregion
そして最後にユーザークラス:
public class User : DependencyObject
{
#region UserLevelProperty
public UserInfo.UserLevel Level
{
get { return (UserInfo.UserLevel)this.GetValue(LevelProperty); }
set { this.SetValue(LevelProperty, value); }
}
public static readonly DependencyProperty LevelProperty = DependencyProperty.Register(
"UserLevel", typeof(UserInfo.UserLevel), typeof(User), new PropertyMetadata(UserInfo.UserLevel.Invalid));
#endregion
ユーザーコントロールの DataContext を KioskController に設定していますが、それは機能しているようです。テキストブロックで単純な文字列バインディングをテストしたところ、問題なく表示されました。
最後に、CurrentUser を更新する呼び出しにより、Setter がトリガーされますが、コンバーターが再度呼び出されることはありません。
CurrentUser.Level = theUser.Level;
コンソール ウィンドウでバインド エラーを有効にしましたが、出力に問題はありません。